An important skill when working with IP subnets is the ability to quickly translate between dotted-decimal notation and CIDR-block notation. In this video, you’ll learn how to quickly calculate these subnet mask notations.
<< Previous Video: Classful Subnetting Next: IPv6 Subnet Masks >>
You may see a subnet mask written in a number of different ways. And in this video, I want to show you how to convert between all of these different representations. You can think of the subnet mask, though, as a contiguous series of ones, where the ones are on the left side of the subnet mask, and the zeros are on the right side of the subnet mask.
So if we have a subnet mask, like this one that has three octets of all ones, we know that this subnet mask is 255.255.255.0. You might also see this subnet mask written as a /24. That means there are 24 bits in this particular subnet mask, in these first three octets. This is also called a CIDR block notation. C-I-D-R that stands for Classless Inner Domain Routing.
You might also hear this referred to as a prefix notation or slash notation because we use the /24 to specify the number of bits. Because we use this slash to designate the number of bits that will be used for the subnet mask. So for a subnet mask of /24, we know that that is the size of the network and the remaining bits, which would be eight bits, in this case, would be the number of bits available for hosts. Let’s perform some conversions between the binary representation of the subnet mask and the CIDR block or the slash type notation of the subnet mask.
I have a subnet mask here written out in binary, which has all ones in the first two octets and all zeros in the last two octets. What we’re going to do is add up the number of ones in this entire subnet mask, which means that we would have 8 plus 8 plus 0 plus 0, which means there is /16– 16 bits that happen to be in this subnet mask. That means that our network is going to be 16 bits long, and the host values are also going to be 16 bits long. Let’s perform the same conversion with this subnet mask, which is all ones in the first three octets, two ones in the last octet, and of course, zeros after that.
If we then add all of those up, 8 plus 8 plus 8 plus the two bits in the last octet, we have a total of 26 for a /26 subnet mask. This means that the network is going to be 26 bits, and the host value will use the six bits at the end. And here’s another binary subnet mask, which is all ones in the first octets, four ones and four zeros in the second octet, and then all zeros after that. We then add up all of the ones, which is 8 plus 4 plus 0 plus 0 for a /12 subnet mask. That gives us 12 bits to use for network addresses and 20 bits to use for hosts on each one of those networks.
If you only have eight bits available in each one of these octets, there’s only a certain number of combinations of these binary to decimal representations you can have. For example, all zeros would obviously be zero. A one and all zeros is going to be 128. Two ones and all zeros is 192 and so on.
So instead of performing a manual calculation every time you wanted to convert between binary and decimal, you could simply write out this chart and very easily be able to convert between them. So let’s take the subnet mask that we used before, which was all ones in the first octet and four ones in the second octet and zeros after that. We know that all ones, if we look at our chart, is 255, and then four ones and four zeros, if we look at our chart, is 240. So the subnet mask would be 255.240.0.0.
We know that there are 12 ones, so the subnet mask will be a /12 CIDR block address, giving us 12 bits for the network and 20 bits for all of the hosts that would be on each network. Let’s use our chart to perform the same calculation with this subnet mask. In binary, it’s all ones in the first octet, all ones in the second octet, and three ones in the third octet.
Well, we know that all ones is going to be 255, and three ones and the rest 0 would be 224, making the subnet mask 255.255.24.0. And if we add up the number of ones, there are /19 for this subnet mask, giving us 19 bits for the network and 13 bits to use for hosts on each of those networks. Let’s do this in reverse, where we have the CIDR block notation, and we want to convert back the decimal representation of that. We have a /26 as our subnet mask.
If we write this out manually, in decimal form, there are 26 ones and then the remaining zeros for the subnet mask. If we look at our reference chart, we know that all ones is 255, and then two ones at the beginning would be 192, making this subnet mask 255.255.255.192. 26 bits for the network address and six bits for the host on each network. And let’s do one last conversion– see if we’ve really got it.
We’ll do a /20 subnet mask. We’ll write this out manually in binary form with 20 ones, and the rest would be zero. We know that the all ones is 255, and a four ones and four zeros, looking at our chart, is a 240. So our subnet mask is 255.255.240.0, making the network 20 bits long and the host 12 bits long.