Subnetting is one of the most important pieces of knowledge an engineer must know. There’s quick ways to subnet but before learning the tricks, it’s important to know what is actually happening in binary.
An IPv4 address consists of 32 individual bits ranging between 0.0.0 – 255.255.255.255. The reason for this is due to 255 being the biggest decimal number that we’re able to express in binary with 8 bits. 1111 1111 = 255.
Classful Address Ranges
Everyone has probably heard of these once or twice. The classes of addresses. Class A, B, C.
Class A: 220.127.116.11 – 18.104.22.168 ( a /8)
Class B: 22.214.171.124 – 126.96.36.199 ( a /16)
Class C: 192.0.0.0 – 188.8.131.52 (a /24)
Now that we know what they are, lets throw them out the window! This is no longer used any longer and now we incorporate classless subnetting called VLSM – variable length subnet masks. However, we need to know the address ranges of the classful subnets due to some older protocols like RIP. (and old people)
VLSM means that the mask for example /24 or 255.255.255.0 determines the subnet size and no longer relies on the Class like A, B, or C to determine the subnet mask.
For instance you can have an address start with the class A IP address of 184.108.40.206 which by old standards would mean that you own all the IP address space of 220.127.116.11 – 18.104.22.168 (16,777216 addresses) but nowadays would be subnetted down through VLSM to maybe a /15 or 255.254.0.0. Which would give us an address range of 22.214.171.124 – 126.96.36.199.
Lets break down the previous example with binary and how it actually works. We used an 188.8.131.52 with a subnet mask of 255.254.0.0 or in CIDR (classless inter-domain routing notation) a /15.
Binary is simply either a 0 or a 1. An IPv4 address has 32 bits ( a bit is a 0 or a 1) cut into four separate chunks called octets. Therefore, an IPv4 address is composed of bits in the pattern of:
00000000.00000000.00000000.00000000 <-- 32 bits This example equals 0.0.0.0
00001000.00000000.00000000.00000000 equals 184.108.40.206 11111111.11111110.00000000.00000000 equals the subnet mask of 255.254.0.0
By looking at the above mask in binary, we can determine which bits are ‘locked’ and are non-permeable. Lets bold the Network ID with the Subnet Mask.
00001000.00000000.00000000.00000000 <- 220.127.116.11 11111111.11111110.00000000.00000000 <- 255.254.0.0
Going from the above, these bold bits are locked and can not be changed. To get the broadcast ID ( the last address in the subnet) we simply flip the unlocked bits.
00001000.00000000.00000000.00000000 <- 18.104.22.168 Original 00001000.00000001.11111111.11111111 <- 22.214.171.124 Flipped
By flipping our unlocked bits our broadcast ID is found of 126.96.36.199.
188.8.131.52 Network ID
255.254.0.0 Subnet Mask
184.108.40.206 Broadcast ID
One more example. 172.16.0.0/19
The /19 represents 19 locked bits meaning they can never change in this subnet. Lets show the the network ID and mask in binary.
10101100.00010000.00000000.00000000 equals 172.16.0.0 11111111.11111111.11100000.00000000 equals /19 or 255.255.224.0
If we flip the unlocked bits we get our broadcast
10101100.00010000.00000000.00000000 equals 172.16.0.0 10101100.00010000.00011111.11111111 equals 172.16.31.255
172.16.0.0 Network ID
255.255.224.0 Subnet ID
172.16.31.255 Broadcast ID
So now that we know what is actually happening at the bit level, we’re now ready to move on to faster ways to subnet. We’ll cover that in my next post Quick Subnetting!