Wednesday, July 22, 2009

How to calculate which subnet a host is on . . .

From, "Classful IP Subnet Calculations", by Josh Gentry, which can be found under "Links Worth Visiting".

Given the IP address of a host and the subnet address for the network, you need to be able to calculate which subnet that host is on. To do this we compare the binary representation of the pertinent octet of the subnet mask witht he binary representation of the corresponding octet in the IP address. Example:

IP address=172.60.50.2
subnet mask=255.255.224.0

50= 00110010
224=11100000

We perform a logical on these two numbers. We will be left with only the bits where there is a one in both octets.

00110010
11100000
--------
00100000=32

This host is on subnet 172.60.32.0.