Calculating IPv4 Subnets and Hosts – N10-008 CompTIA Network+ : 1.4

Before you can use a shortcut to calculate subnet values, it’s useful to understand the binary math. In this video, you’ll learn how to calculate the important values of an IP subnet based on the IP address and subnet mask.


In this video, we’ll talk about how you would calculate IP version 4 subnets and hosts. This video builds on a number of topics covered in previous videos, so make sure you go back and watch the videos on binary math, classful subnetting, and IPv4 subnet masks. If you’ve ever seen a network diagram, then you’ve probably seen a mixture of routers and IP addresses with subnet masks, and each one of these networks is subnetted into its own range of IP addresses.

Well, the question, of course, is why do we go through this process of performing all of these calculations, splitting the network up into these smaller pieces, and having to manage all of these separate IP subnets? Well, one of the most common reasons is that it’s very difficult to connect all devices to all other devices in the world simultaneously. It would require a massive amount of technology to be able to know where every single device happens to be at any particular time.

Instead, we use routers to separate the network into smaller pieces, and we simply send our traffic to the next router, who then determines where the next route would be after that. It’s a much simpler way of being able to manage such a large number of devices on a network, and yet still allow us to communicate to all of these separate endpoints. Prior to 1993, your subnet mask was set automatically based on what your IP address happened to be. This is a class-based subnet method that we very quickly found was not able to be as flexible as we needed on today’s modern networks.

Instead, today we use what’s called VLSM, or variable length subnet masks, where we, the network administrators, can determine what the best subnet mask might be for our particular network. You can think of this as having an entire pie and slicing the pie into smaller pieces, or maybe you have a pizza and you’re cutting the pizza into smaller pieces from there. You’re able to customize, depending on the requirements for the number of networks and number of hosts on your network.

Variable length subnet masking allows us to use different subnet masks, depending on the requirement. So although a network of 10.0.0.0/8 would be a class A network that has that to 255.0.0.0.0 subnet mask, we may want a network with more flexibility. So variable length subnet mask allows us to set a subnet mask of 10.0.1.0/24 or 10.0.8.0/26.

The real question then becomes, what are the size of the slices on the pizza that you’re going to cut? In class-based subnetting, we would have a network address of 10.0.0.0, and the subnet mask would be 255.0.0.0. That is a class A subnet for that particular IP address range. And if you looked at this particular subnet mask in binary form, we would have all 1’s in the first octet and 0’s in the remaining three octets. That means that the subnet mask is to 255.0.0.0, or a /8 that has 8 bits for the network and 24 bits for the host.

But we may want to take this pizza and cut it into smaller pieces, so instead of having our subnet mask separation after that first octet, we’re going to move the subnet mask down a bit until we find exactly where we would like it to be. For example, if we place that right after the third octet, we still have our 8 network bits, but now we’ve created 16 new bits in the middle that are our subnet bits. This leaves us with 8 bits at the end for our host. And if we perform calculations on all of these bits, we can see now that the subnet mask is 255.255.255.0, or a /24.

This is the challenge that the network administrator has is to determine where to draw that line. And it’s this determination on number of subnet bits and the number of hosts bits that you have left over that helps the administrator determine how they should best engineer the subnetting for their network. One of the things we learned in our video on binary math was the powers of 2. For example, 2 to the first power is 2, 2 to the fifth power is 32, and 2 to the 12th power is 4,096.

We can use these powers of 2 to help calculate the number of subnets and the number of hosts that are available, depending on how many bits we might have. The number of subnets can be calculated as 2 to the subnet bits power, and the number of hosts per subnet is 2 to the host bits power minus 2. Let’s use these calculations in a practical example on subletting.

Here in the upper left, we have our numbers of subnets calculation and our hosts per subnet calculation along with our powers of 2 table. Let’s take an example of an IP address of 10.1.1.0/24, and let’s perform some subnetting. We’re going to take that /24 subnet mask and listed out in binary form with 24 1’s and eight 0’s at the end. We also know that this IP address is a class A address, because it starts with a 10 in its first octet, so we know that the default is to have 8 network bits.

But in this case, we’ve specified a 24, so the number of bits that we will use will actually be extended another 16 bits, and those will be our subnet bits. The remaining bits are the 8 bits on the end, and those will be our host bits. Now we can perform some calculations we know that the number of subnets is 2 to the subnet bits power, which means that you have the 16th power. And if we look at our chart, 2 to the 16th power is 65,536.

The next calculation is the host per subnet, which is 2 to the host bits minus 2. We know that we have 8 host bits, so 2 to the eighth power minus 2 is the same thing as 256 minus 2, or 254 hosts per subnet. So for this particular IP address, we know there is a maximum of 65,536 subnets that we can create, and on each one of those subnets, we can put a maximum of 254 hosts.

Let’s do another one. This IP address is 192.168.11.0/26. And that 26 is the same as putting 26 1’s, and then we have six 0’s left over at the end. This IP address starts with a 192, which means it’s a class C address by default, so we will specify the 24 bits that are required for class C. But we would like to also use those last two bits to make up the 26 bits, so we’ll extend that out another 2 bits, and those remaining 2 bits are our subnet bits. That means the last 6 bits are our host bits, and now we can perform that calculation of number of subnets, which is 2 to the subnet bits, or 2 to the second power, or 4 total subnets.

And since our host bits are 6, we can specify the number of hosts per subnet as 2 to the sixth power minus 2, which is also 64 minus 2, or the value of 62. That means, for this IP address of 192.168.11.0/26, this is one subnet that is a maximum of four total. And on all four of those subnets, we can have a maximum number of 62 hosts on each subnet.

This is the same process every time, and it works with any IP address. Let’s take 172.16.55.0/21, and we’ll put all 21 of those bits of the subnet mask written out in binary form. We know that the 172 is a class B address, so the number of network bits would be the first 16 bits of the subnet mask. Then we’ll also extend this out the extra 5 bits that we have, making up the 21 bits of the subnet mask. So our subnet bits are 5, and the remaining bits are the host bits, or 11 total bits.

Performing our calculations, we know that the total subnets is 5 bits, or 2 to the fifth power, 32 subnets total. And the total number of hosts that you can have on a subnet is 11 bits. And if you do the calculation, 2 to the 11th power minus 2 equals 2046 hosts per subnet. You could perform this calculation manually on your exam to determine what the number of subnets and number of hosts might be, but you can see there is a lot of effort that goes into converting this to binary, converting things back to decimal, and then performing these calculations. In the next couple of videos, we’ll show you some different shortcut techniques that can help you perform these calculations very quickly, on your exam or any other time.