Thursday, February 10, 2005

How To Calculate Subnet Masks

Following is an illustration of how subnet calculations work. I had to refresh my memory so I thought I would share:

  • 192.168.168.168 --> This is a 32 bit IP address. 8 bits times 4 segments.
  • 255.255.255.0 --> This is a 24 bit network mask. 8 bits times 3 segments.

For it to make most sense convert the number to binary. So consider an 8 bit segment you can calculate it like this:


Place 1: 0 or 1 = 128
Place 2: 0 or 1 = 64
Place 3: 0 or 1 = 32
Place 4: 0 or 1 = 16
Place 5: 0 or 1 = 8
Place 6: 0 or 1 = 4
Place 7: 0 or 1 = 2
Place 8: 0 or 1 = 1
======================
  Total = 255

I.E. segment 255 would be 11111111, and 0 would be 00000000, and 192 would be 11000000. In the case of the subnet mask being 255.255.255.224. The binary looks like:

11111111.11111111.11111111.11100000

Which leaves the last 5 bits for the host IP address. A network with a subnet mask declared 255.255.255.224 would actually have 8 IP ranges (2^3), with 32 addresses in each. Only 30 are usable for hosts as the the first is the "network" and the last is the "broadcast".


(Last Segment)
-------------------------------------------
000xxxxx -> 00000000 - 00011111 (000 - 031)
001xxxxx -> 00100000 - 00111111 (032 - 063)
010xxxxx -> 01000000 - 01011111 (064 - 095)
011xxxxx -> 01100000 - 01111111 (096 - 127)
100xxxxx -> 10000000 - 10011111 (128 - 159)
101xxxxx -> 10100000 - 10111111 (160 - 191)
110xxxxx -> 11000000 - 11011111 (192 - 223)
111xxxxx -> 11100000 - 11111111 (224 - 255)

It is worth noting that netmask is sometimes identified by using the "network" address slash the number of bits to mask. As example you could represent the above IP ranges like this:


192.168.0.0/27
192.168.0.32/27
192.168.0.64/27
192.168.0.96/27
192.168.0.128/27
192.168.0.160/27
192.168.0.192/27
192.168.0.224/27

Maybe the following is a bit more familiar to you:

192.168.0.0/24 (192.168.0.0 - 192.168.0.255)

No comments: