In my previous blog article I gave a couple of troubleshooting tips on DHCP. I also mentioned that I would show a trick for working out TCP/IP subnets.

There are MANY subnet calculators out there and they are very useful for planning and designing a TCP/IP infrastructure but sometimes you may just want to know how to work out if two machines are on the same subnet.

Take the following IP Address and subnet mask:

172.17.1.15

255.255.0.0

From the above example it's nice and easy to see that the network the IP address lives on is 172.17.0.0 - The dividing line between network and host is obvious and clean.

Now try the same with the following:

172.17.14.12

255.255.252.0

Which network does the IP reside on?

The answer is 172.17.12.0

This can be worked out nice and simply by launching calc in scientific mode and performing an AND operation on the value where the subnet is NOT 255 and NOT 0.

Take these three examples:

172.17.30.99/20

172.17.31.221/20

172.17.32.1/20

What's the subnet mask?

255.255.SOMETHING.0

As 255 uses 8 bits for the subnet mask we can work out that it's 255.255 and the something has 4 bits left over. 11110000 equals 128+64+32+16 which is 240 so the subnet mask is:

255.255.240.0

Now perform the AND function on the 224 octet and you get:

30 AND 240 = 16

31 AND 240 = 16

32 AND 240 = 32

These show that the first two IP address are on the 172.17.16.0 and that the last one is on the 172.17.32.0.0 network. The last IP addres will need a gateway in order to talk back to the first two.

This tip is really meant for the sort of situations where you have problems with two machines talking to each other. It's a 'sanity check' that lets you see if both machines are on the same or different VLANs.

If you want something that can give you a whole lot more then you can download a really nice free subnet calculator