Understanding how to subnet using variable length subnet masks are important for any network administrator. In this video, you’ll learn how to use variable length subnet masks to segment a network into smaller IP subnets.
In this video, we’re going to look at a detailed calculation of subnets and hosts using IP version 4. If you stumbled across this video, I highly recommend you go back and look at our video on binary math, classful subnetting, and IPv4 subnet masks.
As we’ve been going through these subnetting videos, you may be asking yourself, why do we have to go through this process of calculating IP addresses, their mask, looking at default gateways, and understanding what the first and last available IP address might be? Well, that’s because it would be functionally impossible to have one device that would know where every other device in the world might be. Instead, we create smaller networks. And we build routers that are able to get information between all of these smaller networks.
This allows us to communicate to anywhere in the world without knowing exactly where that destination location might be. We simply send out the packet. And the routers every step of the way allow us to get that information to the final destination.
Well, this means that we need to create these smaller networks. And we do this by using a process known as VLSM, or Variable-Length Subnet Masks. As the name implies, these subnet masks are not like the class-based networks that we looked at earlier, which have a very fixed number of bits in the subnet mask. Instead, we can create a subnet mask that has a different number of bits on every network, therefore creating a variable length of a subnet mask.
This means you, as the network administrator, can build a network that is exactly the right size with the right number of networks and the right number of hosts. And you have complete control over what the subnet mask might be for that network. This is a lot like cutting a pizza into smaller pieces. How many pieces do you need in the pizza? Should the pizza be cut in two pieces? Should it be four? Should it be eight? Or should it be even more than that?
If we apply this to IP, we can look at a class A network which has 10.0.0.0 and a subnet mask with a /8. But if we wanted to cut that pizza into smaller pieces, we might have a subnet mask of a /24 or even a /26. Since we’re using a different number of bits than eight in the subnet mask, we’re using a variable-length subnet mask that we can define to be whatever we’d like.
Let’s perform some of this variable-length subnet masking. But let’s first look at the default subnet mask for a class A address. This would be 10.0.0.0. The default is class A, since that starts with the number 10. And the default subnet mask for that would be 255.0.0.0. This would be the default subnet mask if all we did was have classful addressing.
If you were to look at this classful address in binary, the first 8 bits would be 1. And the remaining bits would be 0. In decimal, that means it would be 255.0.0.0. And if you were to use the CIDR block notation, this would be a /8 subnet.
This means that the network bits would be those first 8 bits of the address. And the host bits would be the last 24 bits of the address. Since this is a /8 subnet mask, we are drawing our line after those first 8 bits of the subnet mask. But in reality, of course, we could pick a different number of subnet bits. We just need to decide what works best for our network.
For example, let’s draw our line right after the third octet. This means that we still have our default first 8 bits as part of that class A address. But we’re going to borrow the middle 16 bits as what we call our subnet bits. This means those subnet bits would now be turned into one. And the host section of the IP address would shrink down to 8 bits. This means that the decimal subnet mask would be 255.255.255.0. And the CIDR block notation for this new subnet mask would be /24.
We’ve been doing a lot of these calculations in binary, and then we’ve been converting that binary back to decimal. But that process tends to take time. And one of the faster ways to perform these calculations is to look at a list of the powers of 2. For example, you can look at 2 to the first power is 2. 2 to the second power is 4. 2 to the third power is 8, and so on.
If you want to calculate the number of subnets and the number of hosts, you can calculate the number of subnets as 2 to the number of subnet bits. And the number of hosts per subnet would be 2 to the number of host bits minus 2. That’s subtraction for the 2 means that we are subtracting the number that we would use for our network address and the number that we would use for our broadcast address. Everything in the middle would be our host addresses.
So let’s now use this chart with our powers of 2 to calculate the number of subnets and the number of hosts per subnet. Let’s take the IP address of 10.1.1.0/24. If we perform our calculation in binary, we would write out all 24 of those bits as 1’s. And the last 8 bits would be 0.
The default for a class A address such as this one, though, would normally have our network address as the first 8 bits. But we are moving that line another 16 bits over so that we are borrowing an additional 16 bits for the subnet. That leaves us with 8 bits left over for the host.
If we were to calculate the number of subnets using these powers of 2, we would take 2 to the number of subnet bits. And since we have 16 subnet bits, 2 to the power of 16 is 65,536. If we were to calculate number of hosts per subnet, it’s 2 to the number of host bits minus 2. We have 8 host bits, which means 2 to the 8 minus 2 is 256 minus 2, or 254.
So for this IP address of 10.1.1.0/24, we can have a maximum number of subnets of 65,536. And on each of those subnets, we can have a maximum of 254 devices.
Let’s calculate another one. We’ll look at an IP address of 192.168.11.0/26. If we were to write out that /26, you can see there are 26 1’s. That leaves us with two 1’s in the last octet. And we have six 0’s left over at the end.
If we calculate the class of this address, we look at the first octet, which is 192, which means this is a class C address. That means it has a total number of 24 bits as the network address by default. But we’ve borrowed a couple of extra bits into the last octet. So there are two additional bits available that we will call our subnet bits. And then, of course, we have the last 6 bits available as the host bits.
Let’s perform our calculation again. To calculate the number of subnets, we use 2 to the number of subnet bits. We have 2 bits left over as the subnet bits. 2 to the second power is 4. To calculate the host per subnet, we have 6 bits. So we take 2 to the sixth power and subtract 2 from there. That means we have 64 minus 2, or 62. So for this IP address of 192.168.11.0/26, we can create a total of four subnets. And on each of those subnets, we can have a total of 62 devices.
This same process works with any type of subnet mask. Let’s take, for example, 172.16.55.0/21. If we looked at this in binary, we would have 21 1’s, which means we have eight in the first octet, eight in the second octet, and five 1’s in the third octet. Everything else, of course, would be 0’s. And if we look at this IP address, it starts with 172, which by default would be a class B address.
So by default, the first 16 bits would be your network address. We borrowed some additional bits– in this case, five additional bits– to be our subnet bits. And then everything left would be our 11 host bits. Performing our calculation again, we have five subnet bits. So to calculate the number of subnets, it’s 2 to the fifth power, or 32.
We have 11 host bits left over. So if we calculate that as 2 to the 11th power minus 2, that would be the same as 2,048 minus 2, or a total of 2,046 devices. So for this IP address of 172.16.55.0/21, we can have a total of 32 subnets. And on each of those subnets, we can have a maximum of 2,046 devices.
If you use these powers of 2 to perform these calculations, it can be a very quick way to determine what the number of subnets might be and what the host per subnet might be. But there are some shortcuts available that might get you to these values much faster. And in the next couple of videos, we’ll give you some different options for calculating this process using those shortcuts.