The transition to variable length subnet masks provides efficiency and flexibility with IP addressing. In this video, you’ll learn about classless subnetting and CIDR-block notation.
In a previous video, we talked about class-based subnetting and how IP addresses can be assigned a class A, class B, or class C address. But since 1993, we’ve not used class-based subnetting. Instead, we use classless subnetting. Sometimes you’ll see this referred to as Classless Interdomain Routing, or CIDR.
This classless addressing means that we can assign a subnet mask that doesn’t fall into those same class A, class B, or class C arrangements. And instead of referring to the subnet mask in its decimal form, we can simply refer to it as the number of bits. That number of bits is referred to as a CIDR block notation.
For example, a decimal subnet mask of 255.0.0.0 is the same as a /8 CIDR block notation because it has eight individual bits as part of the subnet mask. So it would be very common to see an IP address written as 192.168.1.44/24. Everything with the /24 is referring to the number of bits in a subnet mask. And a /24 mask would be the same as 255.255.255.0.
When you’re configuring a device, you’re often giving it an IP address, a subnet mask, default gateway, and very often a series of DNS servers. Most of the time, an operating system is expecting you to put the subnet mask in as a decimal mask. So for example, in Windows, you may put the IP address. And then you might add in the decimal version of the subnet mask.
But if you’re using a router or a switch, it may be expecting the CIDR block notation for those masks. So instead of using 255.0.0.0, you would simply input /8. Make sure you check the documentation of the device you’re using to see what notation it prefers for the subnet mask.
As you’ve probably seen in our previous examples of subnet masks, the mask consists of a contiguous series of 1’s followed by 0’s. So the 1’s would be on the left. The 0’s would be on the right. For example, here is a subnet mask. You can see the contiguous set of 1’s on the left and the 0’s that are on the right.
In this example, you can see three separate octets that are set to 1. So there are 24 1’s in this particular mask. And there are eight 0’s at the end. If we were to write this out in decimal, it would be 255.255.255.0. And if you were to write this out in CIDR block notation, you would count how many 1’s are associated with this subnet mask. In this case, there are 24. So the CIDR block notation would be /24.
The subnet mask is obviously used to separate the network part of the address from the host part of the address. So for this particular subnet mask, the network address is 24 bits in length. And the host address is 8 bits in length.
Let’s convert a binary subnet mask to one that is the CIDR block notation for a subnet mask. And we’ll take this subnet mask that we have on the screen, which has all 1’s in the first two octets and all 0’s in the last two octets. If we were to count the number of 1’s in this subnet mask, we have eight in the first octet, eight in the second octet, none in the third, and none in the fourth. That means the total number of 1’s in the subnet mask would be 16. So the CIDR block notation would be /16. This means that the first 16 bits of the subnet mask are associated with the network. And the last 16 bits are associated with the host ID.
Let’s do another one. In this example, the first three octets are all 1’s. But the last octet has two 1’s and six 0’s. So let’s count the number of 1’s in this subnet mask. There are eight in the first octet, eight in the second octet, eight in the third octet, and two that are in the fourth octet. If we count all of those together, we have 26. So the CIDR block notation of this subnet mask would be /26. The /26 means that the first 26 bits of this address are the network part of the address. And the last 6 bits are reserved for the host ID.
And here’s one more. In this subnet mask, we have the first octet of all 1’s. The second octet has four 1’s and four 0’s. And then the third and fourth octets are all 0. Since we are counting number of 1’s, we have eight in the first octet and four in the second octet. And if you count those together, the subnet mask in CIDR notation would be a /12. That means that the first 12 bits are for the network ID. And the last 20 bits would be for the host ID.
We’ve looked at the subnet mask in binary. And we’ve calculated the CIDR block notation. But we often refer to the subnet mask as a decimal value. If we were to convert these binary subnet masks into a decimal value, there are only a certain number of these that you would run into.
For example, all 0’s would obviously be a decimal 0. But anything that starts with a binary of 1 and the rest 0’s would be a decimal of 128. If there are two 1’s, it’s 192. Three would be 224, and so on. This means that you could create a chart that shows all eight of the bits within a single octet and what the decimal equivalent would be.
We can now use that chart to calculate the CIDR block notation and what the decimal representation of that subnet mask would be. So let’s look at a subnet mask of all 1’s in the first octet. There are four 1’s in the second octet. And the rest of this would be all 0’s. If you refer to our chart, you can see that all 1’s is 255, four 1’s and four 0’s would be 240. And then of course, all 0’s would be 0.
And if we were to count the number of 1’s, we know that correlates back to a /12. So a /12 CIDR notation is the same thing as 255.240.0.0 in decimal notation. And of course, since there are 12 1’s, the network section is 12 bits in length, which leaves the remaining 20 bits available for the host ID.
Let’s look at a subnet mask we’ve not seen yet. This one is all 1’s in the first octet, all 1’s in the second octet. There are three 1’s in the third octet. And of course, the rest of this is 0’s. If we look at our chart, we can see that of course, all 1’s is 255. And in the octet that has three of these 1’s, we refer to the chart. That is the same as 224 in decimal. And obviously, all 0’s in binary is the same as 0 decimal.
If we then count the number of 1’s in all of these octets, they all add up to 19. So your CIDR block notation would be /19, which corresponds back to the decimal representation of 255.255.224.0. This, of course, means that the network part of this address is 19 bits in length. And the host section is 13 bits in length.
Of course, we can do this in reverse as well. Let’s say that we have a subnet mask that’s been given to us as a /26 in CIDR block notation. If we were to write this out in binary, that means that we would have all 1’s in the first three octets and two 1’s in the last octet. And if we were to refer back to our chart, all 1’s would obviously be 255. And the last octet that has two 1’s correlates back to a 192 in decimal. So a /26, where your network ID is 26 bits in length and the host ID is 6 bits in length, is the same as a /26 in CIDR block notation, or 255.255.255.192 in decimal.
Let’s do another one, where we’ve been given a /20 in CIDR block notation. That means there are 20 1’s in this particular subnet mask. So your first two octets are all 1. And third octet has four 1’s and four 0’s. And of course, the last octet will be all 0. If we refer to our chart, we know that the decimal version of that binary subnet mask will be 255.255.240.0, which is the same as a /20 CIDR block notation. That means the network part of this address is 20 bits in length, which leaves us 12 bits available for host IP addresses.