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

The process of subnetting an IPv4 address can be calculated quickly with powers of two. In this video, you’ll learn how to quickly calculate the number of IP subnets and hosts per IP subnet.

<< Previous Video: IPv6 Subnet Masks Next: Seven Second Subnetting >>

If you’ve been trying to wrap your mind around the idea of performing the subnet masking using an IP address and a subnet mask, you may be saying to yourself, why are we going through this entire process? Why do we have to subnet the network into all of these tiny different IP subnets? Part of the problem is that we can’t connect the entire world directly to each other. There’s just not enough resources and bandwidth available to do that. Only one device can talk to another device at a time, and we don’t have enough technology to be able to connect together billions of devices so that they were all on the same local network.

Having these separate subnets also provides some segmentation and perhaps the ability to add additional security. We can add a firewall and segment out a particular IP subnet that had servers and that might have a different security posture than an IP subnet that had workstations or printers on it. As we saw in some of our earlier videos, using our class-based subnet mask was very inefficient. We weren’t able to customize the exact size of the network, and we ended up with a lot of leftover IP addresses that wouldn’t be used for anything. By giving the network administrator the ability to customize the size of the subnet mask, they could build out a particular subnetting scheme that provided the exact number of networks and hosts that they needed in their network.

Instead of using these strict class-based subnet masks, we instead commonly use variable length subnet masks on our network. We define this as VLSM. For example, if you had the network– that would be a traditional class A network– we could use variable length subnet masks to have many different kinds of networks, all with different masks. For example, you might have That network has a 24-bit subnet mask. And you might also have a network with a 26-bit subset mask. Those differences in the subnet masks and the ability to design our network in a way that makes sense for what we’re doing, rather than designing it around limitations of an IP address or, what we call, variable length subnet masks.

Let’s see how we could take a traditional class A, subnet mask and customize it so it would be perfect for our network. We’ll start with the network Its traditional class A, subnet mask is You’ll sometimes see this even referred to as Classful addressing, because it’s based on that class A, subset mask. If we were to write out the subnet mask in binary, you would have eight 1s at the beginning and all 0s after that. In decimal, the subnet mask, then, obviously, is or a /8 subnet mask. Based on the subnet mask, then, we have 8 bits that are dedicated as the network address and 24 bits that are dedicated as the host address.

But it would be very unusual to have millions of hosts on a single subnet. Instead, let’s borrow some of those bits, to be able to make the number of networks larger and perhaps the number of hosts on a network a little bit smaller. So instead of applying all 24 of these bits, let’s back out a few of those and leave 8 bits at the end. If we do that, then we have a network that is still 8 bits long. We’ve borrowed 16 of those bits that were left in the host part of the address, and we will use those for different subnets. And then we have 8 bits left over for the host that we would use on each one of those subnets.

Since we’ve moved the bar a bit and added in additional networks, our subnet mask has changed to or /24 network. Since we’re not using the traditional class-based subheading and instead are using our own subnet that we’re defining, we refer to this as Classless addressing. Since we know how many bits are part of the network side of the IP address and how many bits are part of the host side, we can very quickly calculate the total number of subnets available and the total number of hosts available, by using powers of 2.

We wrote a chart like this in an earlier video, where we took 2 to the first power, 2 to the second power, 2 to the third power, all the way through to the eighth power. And of course, you could continue this all the way through to the 16th, and even further out. You would, of course, start with 2 to the first power, which is a 2. You would double that to 4, double it to 8, double it to 16, and so on. So you could create a very easy reference chart to use, when you’re trying to perform some of these subnetting tasks.

To use this chart, we would look at the number of subnet bits that we’ve borrowed and perform 2 to that value to determine the total number of subnets that might be available to us. Then, to determine the number of hosts available per subnet, we would use 2 to the host bits power, and then subtract 2 from that. One of those will be the subnet address, and the other will be the broadcast address. Everything left is the available number of hosts on each individual subnet.

So let’s use those charts to be able to quickly determine what these values might be on an IP subnet. We’ve got our number of subnets here, which is 2 the subnet bits power, and hosts per subnet, which is 2 to the host bits power minus 2. And here at the bottom, we have our powers of 2 chart.

Lets use the IP address If we were to write out the /24 subnet mask, we have 24 1s, and then eight 0s at the end. We know that, because this IP address starts with a 10, that this is traditionally a Class A. So we start with those first eight bits that are associated with a Class A, subnet mask.

We are then going to move our bar down to 24 bits, giving us 16 bits in the middle that we could use to calculate different subnets from that. And of course, we have the 8 bits at the end that we’ll use to assign to different devices on each individual IP subnet. To determine, then, how many total subnets we could create from this particular mask, we’ll look at these 16 bits, and we’ll use 2 the 16 power. And if we look at our chart, that is 65,536 possible networks that you could create from this subnetting.

Now that we know how many networks we can create, let’s determine how many hosts that we can have on each individual network. We’ve got 8 bits available to use as hosts bits, and our formula is 2 to the host bits minus 2, so 2 to the eighth minus 2. If we look at 2 to the eighth is 256, we subtract 2 from that, then the total number of hosts that we could have on any of these individual subnets is 254 maximum hosts.

Let’s perform the same calculation with a different subnet and see what the results might be. In this case, we’ll take The /26 means that we have 26 1s in the subnet mask, and that leaves us with six 0s at the end of the subnet mask. If we were to look at this address that starts with a 192, that means the traditional class-based subnet would give us 24 bits to be able to use for the network. This, obviously, is 26 bits long for the subnet mask, which gives us two additional bits at the end to use for subnetting. We’ve gotten, then, 6 bits at the end that we can use to calculate host values for each individual subnet.

Using our powers of 2 chart, we can see that we’ve got two subnet bits available. So 2 to the second power is 4, which means, from this subnetting, we can create four individual IP subnets from that /26. We have 6 bits available for hosts, and 2 to the sixth power is 64. We subtract two of those for the subnet address and the broadcast address, leaving us with 62 devices per IP subnet.

Let’s use this same process to calculate another subnet. In this case, we use The /21 at the end means that we’ve got 21 subnet bits that are set, and the rest of the bits would be 0. We know that the 172 at the beginning of this IP address means that this would traditionally be a Class B address, and the subnet mask would be 16 bits long. That means we have 5 bits to use as subnetting bits, and the rest of the bits would be 11 bits leftover, to be used for hosts.

If we perform our calculation for the subnet, we’ve got 5 bits available. So 2 to the fifth power is 32. We could create 32 individual networks from this particular subnet mask. And we’ve got 11 host available per subnet. And performing those calculations would be 2 to the 11, or 2,048 minus 2, leaving us 2,046 devices per subnet.