Magic Number Subnetting – N10-008 CompTIA Network+ : 1.4

The “Magic Number” process of IP subnetting is a popular shortcut that requires a minimal amount of math. In this video, you’ll learn the magic number method and how to optimize the method during an exam.


In previous videos, we’ve looked at the process for manually subnetting an IP address. For example, let’s take a common question like this one, where we have a network that has given us an IP address assignment of 192.168.1.0/24, but we need an IP addressing scheme with more than one network address and the support of 40 devices per subnet. How can we subnet this network address to give us multiple networks but still allow for 40 devices per subnet? You could certainly calculate this manually by writing down the CIDR notation, determining what the decimal mask would be associated with that CIDR block notation, and then manually writing out what the binary version of that subnet mask is.

You could also calculate the number of networks and the number of hosts per network based on that particular subnet mask. And then you could calculate additional networks by adding onto the CIDR notation and performing the same calculations for each possible scenario. This question that asked for 40 devices per subnet. So after creating this chart, we can then look at the host per subnet. We can see that a /27 only supports 30 devices per subnet, but a /26 allows for four networks with a total of 62 hosts per network on each of those four subnets.

We could then perform the same calculations that we did in a previous video, where we had that IP address and subnet mask. We then wrote down the binary version of both of those and designated what portion of the subnet mask was the network part of the mask, the subnet bits that we were able to borrow, and then the host bits that were left over at the end.

You can see in this example, there were 24 network bits, there are two subnet bits, and six host bits. Now, we can perform those calculations that we did from the previous video. To determine the total subnets, we take the 2 to the second power because we had two subnets available. That gives us a value of four total subnets. And then we can calculate hosts per subnet, which, in this case, is six bits in length, which would be 2 to the sixth power minus 2 or 64 minus 2, which gives us 62.

After performing that entire process, you now have everything you need to be able to answer that question. But part of the challenge with this is that it takes quite a bit of time to perform these conversions. Ultimately, we’re looking for four very important addresses we want the network address or subnet ID. This is the first address that is in the subnet. We want the broadcast address, which is the last IP address in the subnet range. We want the first available host address, which is one more than the subnet ID. And then we want the last available host address, which is one fewer than the broadcast address.

To be able to calculate this in binary, we would have to write out all of the binary combinations for that network address and subnet mask to be able to determine what all of the different networks are, all of their broadcast addresses, the first host, and the last host for each of those individual subnets. And as you can see, just doing a very small number of subnets– four separate subnets– can result in a large amount of calculations and conversions between decimal and binary. And on your exam, you don’t have time to create these large and extensive charts. So we need some type of shortcut that can make this process much quicker.

One popular shortcut that’s used for this subletting process is called the Magic number method. This is a relatively straightforward process where you can do most of the math in your head or the minimal amount of math that you would need to be able to calculate this particular subnet. You may find that there are some charts that might help you. And in this video, we will show you how to perform these calculations in your head. And we’ll show you what these calculations would look like if you had a chart available.

If you were to write down all of the different CIDR block notations and they’re correlating decimal subnet mask, you can create an extensive chart with all of that information inside of it. But one of the things you’ll notice is that there are some repeating values. For example, a /9 is 255.128.0.0. And if we look down at /17, we can see that 128 shows up again. There’s a lot of repeating processes involved in calculating the subnet masks, and we can take advantage of this by using that as a shortcut in this magic number method.

If you wanted to create a very quick chart that could help you calculate the CIDR block notation to decimal version, then you can write out something like this that uses the /9, /17, and /25 to show you, in the interesting octet, that the number you would use to convert to decimal is a 128. We can use a chart like this as we go through the magic number method or really any method that you use to perform any type of subnetting shortcut.

If you wanted to create a complete chart for the magic number method, you would add another row for the magic number. Here, we’ve turned this on its side so we can see the CIDR block notation for what we call our interesting octet number 2, number 3, and number 4. And you can see all the slash values associated with those octets.

Then for each of those octets, you can see the subnet mask that would be used for that interesting octet. And as you’ll find out in a moment, you’ll be able to use a magic number value for each of those. And we can calculate that in this row. The magic number method is starting at 128. And then you divide that in two for each one of these. So it would be 128, 64, 32, 16, 8, 4, 2, and 1.

This chart will give you almost everything you need to perform the magic number method without having to calculate a lot of these details in your head. If you’re someone who is able to memorize the CIDR block notations very well, then you could easily have all of these values in the first three rows and the last row committed to memory. Then, the only thing you would have to remember is the magic number row.

Another chart that’s useful to have for calculating host ranges is one that separates out all of these different ranges and gives you the starting and ending numbers. For example, in a host range of 128, we have two separate blocks of host that we could use between 0 and 127 and then 128 to 255. The next block would be a block of 64 addresses– 0, 64, 128, and 192.

This might be relatively easy to remember until you get into the smaller blocks. For example, if it’s an address range of eight hosts per subnet, then you’d have to remember 0, 8, 16, 24, 32, 40, 48, 56, 64, and so on. If you’re very good at multiplication and division, then you may not need this chart. But if you’re someone like me that needs a chart to give you the answer without having to perform the math, you might want to spend a minute or two at the beginning of the exam to create this chart.

However, with the magic number process, you may find that these charts are unnecessary, and you can perform most of the calculations in your head. The steps involved at learning how to subnet with the magic number process are these. We start by converting the subnet mask to decimal. So if you’ve been giving a CIDR block notation, you need to understand what the decimal notation of that would be.

We would then need to identify what we call the interesting octet. And I’ll explain more of that in just a moment. We would then calculate our magic number based on the values in that interesting octet. And that’s very often a calculation of 256 minus the interesting octet value. You would from there calculate the host range, calculate the network address, and calculate the broadcast address. Let’s run through the magic number process now and see how it differs from performing exactly the same subnetting process in binary.

The first thing we want to do is to identify the subnet ID. We would need four octet columns. And in each one of these rows, we’re going to add the subnet mask. We’ll determine an action that will perform to that subnet mask. We’ll put the IP addresses in that we will be submitting. And we’ll determine what the subnet ID is in this bottom row. Let’s start with the IP address of 165.245.77.14. And that device has a subnet mask of 255.255.240.0. So let’s add our subnet mask– 255.255.240.0– and let’s add our IP address– 165.245.77.14.

Our first step in finding this subnet ID is to look at the subnet mask. And if that subnet mask is 255, we want to perform a copy action on the IP address and simply copy the IP address down to the last row. We’ll do this with all of the subnet masks that are 255. And in this case, that would be our first two octets.

Then, we want to find any octet of the subnet mask that happens to be 0. We’re going to also copy down not the IP address, but we’re going to copy that 0. So now, we have numbers that are in our first and second octet and another value in the fourth octet. The only one that we haven’t touched is our third octet, where the subnet mask happens to be the value of 240. If there is a value that’s not 255, and it’s not 0, then we are going to identify that octet as our interesting octet.

Now that we know our interesting octet, and we know what subnet mask happens to be in the interesting octet, we need to perform a calculation. Let’s take the number 256, subtract from that the subnet mask value that’s in our interesting octet. And in this example, it would be 256 minus 240, which gives us a value of 16. We call this value of 16 our magic number. This magic number is the number of hosts that are on this particular subnet.

If we look at the chart that we created earlier for the values of 16, we can see that they range from 0, 16, 32, 48, 64, and so on. We know that the value for our IP address is 77. So if we look in our range for where 77 might sit, it is between 64 and 80. This means that our subnet ID in this particular example is 64. And we can bring that down to show the subnet ID of 165.245.64.0.

Now that we know our subnet ID, we need to calculate our broadcast address. And we’ve changed our chart just a little bit. We have our subnet mask at the top and the action row as second, but our third row is now the subnet ID that we just identified, which is 165.245.64.0. And we’re going to try to determine the broadcast address.

This process is very similar to what we just did to perform that subnet ID calculation. We’re going to look at the subnet mask. And if it’s 255, we copy down the subnet ID. So in this case, that first column would be copied down, the 165. Since the second column also shows a 255, we will copy that 245 and bring it down into the last row. If our subnet mask happens to have a 0, we’ll identify that as a zero subnet mask.

And instead of bringing down the 0 since this is the broadcast address, we’re going to bring down the value of 255. This means that we have three of the four numbers we need. And since one of these numbers in our subnet mask was not a 255, and it was not a 0, then we again have an interesting octet. And of course, we knew that the third octet was the interesting octet based on the previous calculation that we did in the last slide.

Now, we need to calculate the broadcast address. And this follows exactly the same process we did earlier to find the magic number. We take the value 256, we subtract from that the subnet mask. And in this case, we come up with the value of 16. In this case, we’re going to calculate a broadcast address. And the way that we calculate that is by using this magic number by taking the subnet ID, adding to that the magic number, and then subtracting 1 from that value.

This means that the value for the broadcast address in that interesting octet would be 64 plus 16, which is 80. You subtract 1, and you get the value of 79. Our broadcast address then is 165.245.79.255. As you can probably tell already, there are a lot of opportunities to be able to perform some shortcuts. And in our next example, we’ll take advantage of some of those opportunities.

We now know our IP address, our subnet mask, our subnet ID, and our broadcast. Let’s find out what the host range would be for this particular network. We don’t have to refer back to our chart at all for this. Instead, we’ll find the subnet ID and add 1 to it. We know that our subnet ID is 165.245.64.0, which means that the first host would be 165.245.64.1.

The last host is the broadcast address minus 1. So again, we can do this with no additional calculations. We simply take 165.246.79.255, subtract 1, and that gives us the value of 165.245.79.254. Now, we have all of the values that we need to be able to perform our calculations. We have our IP address, our subnet mask, our subnet ID, our broadcast address, the first host, and the last host on that subnet.

Let’s perform another subnetting example. Except this time, let’s take advantage of a few shortcuts that might be available. We use the IP address of 10.180.122.244 and a subnet mask of 255.248.0.0. We’ll start by adding our subnet mask into our chart and our IP address into our chart. We’ll identify all of the masks that have a 255 and copy down the IP address from there. And we’ll look at any subnet mask tests that have a 0. We’ll bring down the 0 for each of those columns. Our interesting octet in this case would be the second octet that has the value of 248.

We’ll perform our magic number calculation by taking 256, subtracting the subnet mask of 248, and determine that our magic number is 8. If we are able to look at our chart, of all of those values of 8 or you’re able to calculate the multiples of 8 in your head, you can see that the 180 is the IP address we’re looking for. So we need to find the starting address for that particular block. 180 is down in this chart under the block that starts with 176, so we’ll put the 176 into our chart, which means our subnet ID is 10.176.0.0.

We perform a similar process to find the broadcast address. And we’ve replaced the IP address with the subnet ID row. And of course, we’re going to look at any of the subnet masks that have a 255 or a 0. If there’s a 255, we bring down the subnet ID. And if there is a 0, we bring down the value up 255.

In this particular case, the first column, we bring down the subnet ID of 10, and the third and fourth octet, we bring down the values of 255. And of course, as we saw previously, our interesting octet is the second octet. We perform our magic number calculation again. 256 minus 248 gives us the same magic number of 8.

Since we already knew that, we could have possibly skipped this step at this point. And we need to calculate the broadcast address for that second octet by taking our subnet ID, adding the magic number and subtracting 1. In this case, our subnet ID is 176. We add the value of 8, subtract 1 from that to give us a value of 183.

So our broadcast address for this subnet is 10.18.255.255. Calculating the first available host and last available host then is simply adding 1 to the subnet ID and subtracting 1 from the broadcast, which means that our first host is 10.176.0.1, and the last host is 10.183.255.254.

If we refer back to the chart that I mentioned earlier in the video, we can speed this process up a bit. Let’s take the IP address of 172.16.242.133/27. Let’s first find the /27, and we can see that the subnet mask for that interesting octet is 224. So our subnet mask would be 255.255.255.224 because we know that the interesting octet was octet 4. We can then either calculate the magic number, which would be 256 minus that 224, or we can refer to our chart where we’ve already written in the magic number is 32.

We know from our chart that a /27 means that our interesting octet is octet 4. And in that octet, we have the value of 133. If we go to a chart that shows us those 32 hosts per subnet, we can calculate where that 133 might be. And it starts with a subnet that has a 128. That means that the 128 is the beginning of the subnet, and 1 minus 160 would be the end of that subnet.

Let’s now summarize all of this subnetting information that we’ve discovered. We started with this IP address of 172.16.242.133/27. We converted the /27 from that CIDR block notation to decimal, which means that our subnet mask is 255.255.255.224. We also calculated our magic number, and we know that our magic number is 32. We also calculated, based on where our 133 sits in those values of 32 devices per subnet, that the network starts with a 128.

So your subnet ID is 172.16.242.128. And the broadcast address is 128 plus 32 minus 1, meaning that your broadcast would be 172.16.242.159. We can then now based on the subnet ID and the broadcast address add 1 to the subnet ID to get your first IP address and subtract 1 from the broadcast to get our last IP address. So we now have all of the values we need to understand this particular subnet of 172.16.242.133/27.

If you think the magic number method is one that works best for you, then grab some additional IP address ranges and CIDR block notations and run through this process a number of times. You’ll find very quickly that you’re able to find your own shortcuts, identify where you can speed through this process, and you’ll be able to perform these subnet tasks very quickly on your exam.