Magic Number Subnetting – CompTIA Network+ N10-009 – 1.7

There are many different shortcuts that network administrators use to quickly calculate IP subnet information. In this video, you’ll learn about the magic number method of IP subnetting.


If you’ve been with us with the videos just prior to this one, then you’ve learned a lot about subnetting, masks, CIDR block notation, and other important fundamentals when it comes to subnetting via IP version 4. All of that work has brought us to this point, where we can start to answer questions like this one. Here’s a network layout. And it says, here’s your IP address assignment. We’ve been given the IP address of 192.168.1.0/24.

And this says we need an IP addressing scheme with more than one network address that can support 40 devices per subnet. That is the optimal number we’re looking for. And we need to determine how to subnet this network address to be able to get 40 devices per subnet.

Now, you could, of course, write out all of the possibilities in decimal and binary and be able to calculate what the differences are with the number of networks and the number of hosts per network. For example, if you look at the default subnet mask that we were given, which is 255.255.255.0, you can see this is the binary representation of that subnet mask, and the CIDR notation, which is a /24. That gives us one single network with 254 hosts per network.

If we borrow 1 bit from the host side so that we are 255.255.255.128 as our subnet mask, or a /25, we would be able to create two networks with 126 hosts per network. We are getting closer to that number of 40. Let’s keep going by borrowing another bit so that our subnet mask is 255.255.255.192, or a /26. This allows us to have four networks with a total of 62 hosts on each of those subnets.

This is certainly getting close to 40. But let’s go one more step to see if we’re getting even closer to that 40 value. The next step would be to borrow one more bit from the host side. So now we’re borrowing three subnet bits, which means our subnet mask is 255.255.255.224, or a /27.

If we subnet in this way, we can have a maximum of eight networks. But it would only allow for 30 hosts per network. This means that the optimal subnet mask, if we’re looking for a total of 40 devices per subnet, would be the next one up, or the /26, which would give us four networks and a maximum of 62 hosts per network.

Now, we can certainly speed this process along by performing a calculation based on powers of 2. Let’s look to see how we might do that. We have a starting IP address of 192.168.1.0 and a subnet mask of 255.255.255.192. And based on this information, we can show the network address and the subnet mask in binary. And you’ll notice, in the subnet mask, we have the default number of bits for that address plus the two extra bits that we borrowed from the host side.

Visually, you can see where the 24 subnet bits might be, the two extra bits we borrowed for the subnet, and the six bits that are left over on the host side. If we were to now calculate the number of subnets and the number of hosts per subnets using this powers of 2 formula, we would take 2 to the second power, because the second power would be 2 bits, and that would be a total of four networks. We would determine the number of hosts per subnet by taking those six host bits that are left over at the end and calculating 2 to the sixth power minus 2, which would be 64 minus 2, or a total of 62 hosts per subnet.

This is a relatively straightforward way to calculate the number of subnets and the number of hosts per subnet. But it requires you to perform a binary conversion and then count the number of bits to be able to calculate what that total might be at the end. There are some shortcuts that we can use. And in this video, we’re going to look at a shortcut that uses the magic number method.

These calculations are intended to give us four separate pieces of information. First, we need the network address, or subnet ID. This would be the first address in the subnet. We also need a broadcast address. This is the last address in the subnet. We need the first available host address. This is an address that we can assign to a device on this subnet. And then we need the last available host address. We need to be able to calculate these as quickly as possible.

Now, obviously, we could calculate this by converting everything to binary, looking at the subnet bits, and then calculating for every possible scenario what this particular network address might be and the subnet mask for each one of these. And for this particular IP address, where we determine there were four separate subnets, these are all the calculations that we would need to do to be able to calculate all of that information. For all four of those subnets. You can see, looking at this screen, that there are a lot of separate binary-to-decimal conversions you’d have to do just to calculate those specific details for all four of those subnets.

We can simplify this process by using the magic number shortcut. This allows us to perform subnet calculations very quickly. And very often, we can do all of these calculations in our head. There’s still a little bit of math involved with the magic number method. But it’s limited to powers of 2 and some very simple addition and subtraction. You could even create a few charts that might help you with the process. But once you get accustomed to using this method, you’ll find that you memorize very easily what’s in the charts. You may not have to write them down at all during your exam.

One chart that might help you is a chart that easily converts between a CIDR block notation and the decimal subnet mask notation. You can see an example of this might be to use a /9 is 255.128.0.0. /10 is 255.192.0.0, and so on. You will notice that there are some patterns after a while. For example, a /9 has the 128 as the number that is a bit different than a 0 or a 255. And a /17 also has a 128. So we could write this chart in a simplified form that shows a /9, a /17, and a /25 use the 128 as the decimal value.

In the magic number method, we have a number of different tasks that we perform based on the octet that we’re working with. So we might want to modify this CIDR-to-decimal chart to have something that’s a little bit different. For example, if you wanted to see the CIDR notation for interesting octet 2, you can see it ranges from a /9 through /16. The CIDR block notation for interesting octet 3 would be /17 through /24. And the CIDR block notation for interesting octet 4 ranges from /25 to /30.

You notice that we don’t use /31, by default, because it doesn’t leave any room for any hosts on the subnet. And we don’t use a /32, because that leaves 0 bits available for any hosts. For each of these columns with the CIDR block notation, you’ll notice there is a magic number. And in a moment, we’ll learn how to use that magic number value. We can also put in this chart the subnet mask for an interesting octet. And you can see those mask values are also listed as well, starting at 128 and working all the way up to 255.

Optionally, you could also create a host range chart, where you can take an address block and then separate out what the differences are for that particular block. For example, an address block of 128 splits the network into two different pieces, 0 through 127 and 128 through 255. An address block of 64 hosts per block would be 0 through 63, 64 through 127, and so on. And you can continue this process with a host block of 32 hosts, 16 hosts, 8 hosts, and so on.

So let’s see how the magic number method works. It’s a series of steps. And once you go through these a couple of times, they become very second nature. The first step is to convert the subnet mask to decimal, if it’s not in decimal already. From there, we need to identify the interesting octet. And we’ll talk about the interesting octet in just a moment.

We then need to calculate the magic number, which is 256 minus the value of the interesting octet. We could then calculate the host range based on that, identify the network address, which would be the first address in that range, and then identify the broadcast address, which would be the last address in that range. So now let’s take an IP version 4 subnetting problem and answer this problem using the magic number method.

We’ll start with this IP address of 165.245.77.14. And we’ve been given a subnet mask of 255.255.240.0. Our first step would be to put the subnet mask into the chart. And you can see that it’s already in decimal form. So we simply need to copy it over with 255.255.240.0.

We can then also fill in the IP address that we’ve been given, which is 165.245.77.14. From here, we can start to make some decisions about what to put into this chart. For example, if the mask is 255, you simply copy the IP address down. So in this case, the mask is 255 in the first octet. So we’re going to copy that down, which means our subnet ID will be copied down with the same number that’s in the IP address row.

Let’s perform that same task again with the second octet. It is also 255. So we’re going to copy that through. This 245 then will be brought down into the subnet ID row. We no longer have any octets with the 255. So our next step would be to look at any octets where the mask is 0. And if the mask is 0, we bring that 0 down to the subnet ID row. In this case, our last octet does have a 0. So we’re going to copy that 0 all the way down and put it into the subnet ID row in the last octet.

In our example, the subnet mask in the third octet is a 240. That is obviously not 0 and not 255. So that octet is our interesting octet. Now that we know the interesting octet, we can use that to calculate the subnet ID value for that particular octet. To be able to do that, we need to subtract the interesting octet subnet mask from 256.

In our interesting octet, the subnet mask is 240. So if we subtract 240 from 256, we have the value of 16. This means our magic number is 16. And there would be 16 hosts available on that particular subnet. If we put our chart at the bottom that shows the 16 different hosts that you would have and the delineation between each one of those subnets, you can see that we have a range between 0 and 15, 16 through 31, 32 through 47, and so on.

Now, if we look at the IP address, we can see the IP address is 77. And if we look on our chart, we can fit the 77 IP address in the range between 64 and 79. Since we’re trying to determine the subnet ID, we take the very first number in that particular range, which would be 64. And we add that 64 into that subnet ID in our interesting octet. So for the IP address, 165.245.77.14 that has a subnet mask of 255.255.240.0, the subnet ID is 165.245.64.0.

Of course, not only do we need to know the subnet ID, but we also need to know the broadcast address. To calculate the broadcast address using the magic number method, it’s a very similar process. We use the same chart with the same subnet mask and the subnet ID. But at the very bottom, we have broadcast address instead of subnet ID.

The rules for determining the broadcast address are very similar to the rules we used for the subnet ID. If the subnet mask is 255, we copy the subnet ID all the way down into the broadcast address row. We have two of our octets that show a 255. So we’ll do this for the first and the second octet.

Here’s where the rules are a little bit different when calculating the broadcast address versus calculating the subnet ID. If the mask is 0, we’re going to write into that column a 255. And of course, if the subnet mask octet doesn’t contain a 0 and it doesn’t contain a 255, then that octet is our interesting octet. This will obviously be the same interesting octet when we’re calculating the broadcast address as it was when we were calculating the subnet ID.

To calculate the magic number, we perform the same process that we did earlier. We take 256. We subtract from that the value that’s in that interesting octet mask, leaving us with a magic number of 16. To calculate the broadcast address for that interesting octet, we take the subnet ID. And we add the magic number and subtract 1.

So in this example, we use 64 because that is the number in our subnet ID. We add 16, which is our magic number. We subtract 1. And that leaves us with 79. So in this example, the broadcast address is 165.245.79.255. Now that we know the subnet ID and we know the broadcast address, calculating the first available IP address and the last available IP address is relatively straightforward.

To calculate the first host, we would take the subnet ID and add 1. So the first address on the subnet is 165.245.64.1. To find the last usable address on the subnet, we take the broadcast address and subtract 1. So the last usable address on this subnet is 165.245.79.254. And that is the magic number process. Without doing any type of conversions between binary and decimal, we were able to calculate the subnet ID, the broadcast address, the first available IP address, and the last available IP address.

Let’s see how well we can use this magic number method with another example. We’ll use the IP address of 10.180.122.244. And the subnet mask is 255.248.0.0. We will first fill in our chart. So we’ll put our subnet mask in that mask row. And we’ll put our IP address in the IP address row.

We’ll now look at our subnet mask. And everywhere there’s a 255, we will use that to copy down the IP address. So in this case, in the first octet, we’ll copy down that value of 10. Every place there is a 0, we’re going to copy down the 0 and put that into the subnet ID row. And the third and the fourth octets both have a 0. Since we don’t have a 0 or a 255 in this second octet, that means that this octet is our interesting octet.

To calculate the magic number, we use 256. Subtract the value that we have in that subnet mask range, which means we use 256 minus 248. So in this example, our magic number is 8. This means that each subnet has a total of eight IP addresses that can be assigned, including our subnet ID and our broadcast ID. And we’ve put the chart at the bottom that separates this into those multiples of eight.

Now we need to find the IP address that is the starting for this particular block. If we look at our interesting octet, we know that the IP address is 180. So if we look at our chart, we can find that 180, which is in the block starting with 176. Since that starts with 176, we can simply fill that in, which means the subnet ID for this example will be 10.176.0.0.

Now we need to find the broadcast address for this example. We’ll use a similar process we did before, where if we had a 255 in the list, we’re going to copy and bring down that subnet ID. So the first octet, we’ll simply copy down the number 10. Anywhere that we have a 0, we’re going to copy down and put a 255. And we have 0’s in both our third octet and our fourth octet.

As we already know, the second octet is our interesting octet. So we’re going to perform our calculation, taking 256, subtracting 248 from that, meaning our magic number is 8. This is obviously the same magic number we calculated earlier. To calculate the broadcast address, we need to take the subnet ID, add the magic number, and subtract 1. So the example here would be 176 plus 8, since that’s our magic number. And if we subtract 1, that leaves us with a number of 183. We’ll add this to our broadcast address row, which means the broadcast address for this example is 10.183.255.255.

Now that we’ve calculated the subnet ID and the broadcast address, it’s relatively easy to determine the first host ID, because we take the subnet ID and add 1. So the first available host on the subnet is 10.176.0.1. To determine the last address, we take the broadcast address and subtract 1. So in this case, it would be 10.183.255.254.

Hopefully, now you can see that the magic number method is a bit faster than going through the steps of converting to binary and then back to decimal again. But there are some ways to make this process even more efficient. If you’ve already created a chart that shows all of the possibilities of an interesting octet CIDR block notation and has the magic number predefined along with the subnet mask for the interesting octet, you can perform this entire process in one single chart.

Let’s take the example of 172.16.242.133/27. If we look at our predefined chart, we know that /27 falls into the CIDR block notation for interesting octet 4. This means that octet 4 will have a decimal value of 224. So if we wanted to write out the entire subnet mask, it would be 255.255.255.224 because 224 is in that interesting octet number 4.

The process for calculating the magic number is exactly the same as it was before. We take 256. We subtract that subnet mask in the interesting octet, which in this case is 224, which means our magic number is 32. There are 32 available addresses on each subnet of this particular IP address and subnet mask combination.

Here’s our chart, which is written out with 32 numbers in each of those sections. And if we look at our IP address that has a 133, we can move forward to where the 133 would be. And it is in the block that starts with a 128. Since we know it starts with a 128, that means that we can now change our fourth interesting octet to be that value as the subnet ID. So the subnet ID in this example would be 172.16.242.128.

If you recall from our earlier calculations, to be able to calculate the broadcast information, we need to take the subnet ID value in the interesting octet, add that to the magic number, and subtract 1. So we’ll take 128. We’ll add 32 to make 160. We’ll subtract 1. And that makes 159. So the broadcast address on this subnet is 172.16.242.159.

Now that we know the subnet ID and the broadcast, we can calculate the first available IP address and the last available IP address. We add 1 to the subnet ID to determine the first IP. So the first IP would be 172.16.242.129. If we subtract 1 from the broadcast address, we would get 172.16.242.158. So there is the faster way to be able to calculate our subnet ID, our broadcast address, the first IP address, and the last IP address using the–