Jim's guide to IP Subnetting

IP subnetting, interesting, logical, but a shit to remember when someone asks you to explain it! To understand IP subnetting you need to understand how and why IP uses a hierarchical system and why we need to subnet large networks behind our internet routers (information hide).

Here's my notes on IP subnetting

Remember the 3 usable IP classes:

Decimal
CLASS A: 1 - 127
CLASS B: 128 - 191
CLASS C: 192 - 223

Binary (Leading bit)
CLASS A:
00000001 - 01111111
CLASS B: 10000000 - 10111111
CLASS C: 11000000 - 11011111

Default Subnet's
CLASS A: 255.0.0.0 - 11111111.00000000.00000000.00000000

CLASS B: 255.255.0.0 - 11111111.11111111.00000000.00000000
CLASS C: 255.255.255.0  - 11111111.11111111.11111111.00000000

Subnetting a class B address with a (/24) 255 bit mask.

IP            182.16.18.60     =    10110110.00010000.00010010.10111111
MASK    255.255.
255.0    =   11111111.11111111.11111111.00000000
                                                                                                ^
                                                                                             255

To find out the number of possible subnets:
2 to the power of (number of masked bits) -2 = max number of subnets.
In this case that means 2 to the power of 8 = 256 -2 = 254.
You must subtract 2 because we can't use
all 0's or all1's.

(Note: Most TCP/IP stacks will allow these subnets however. So it's up to you. Cisco router's do not use them by default but can be programmed to do so).

To find out the number of possible hosts per subnet we do a similar calculation:
2 to the power of (number of unmasked bits) - 2 = max number of hosts.
So that's 2 to the power of 8 = 256 -2 = 254.
So in this scenaro using a /24 bit (255) mask we get 254 hosts on 254 subnets.

Now lets do that again using a (/28) 240 bit mask.

IP            182.16.18.60     =    10110110.00010000.00010010.10111111
MASK    255.255.
240.0    =   11111111.11111111.11110000.00000000
                                                                                                ^
                                                                                              240

First, how do we get 240?
Decimal to binary math:

128    64    32    16    8    4    2   1
  1       1       1      1   
0    0    0   0

Now, count the decimal bits that have a masked bit.

128+64+32+16 = 240.

Now, how many Subnets?
Well, 2 to the power of 4 masked bits = 16 - 2 = 14 subnets.
And hosts, 2 to the power of 12 = 4096 -2 = 4094 hosts.

And to work out where the subnet begins?
256 - subnet mask = first subnet, so 256 - 240 = 16, so the first subnet ID is 16 then 32, 48, 64...

One way to figure out which subnet ID your IP belongs to is to do the following calculation.

IP            182.16.18.60     =    10110110.00010000.00010010.10111111
MASK    255.255.240.0    =   11111111.11111111.
11110000.00000000
                                                                                        
       ^
                                                                                              240

This works like this:
3rd octet of the IP              
0       0      0       1    0    0    1    0
Subnet mask                      1        1      1       1    0    0    0    0
Decimal conversion        128    64    32   
16    8    4    2    1

Which as you can see means that our 182.16.18.60 IP belongs on the first subnet ID 16

 

jimparker.co.uk