Transcript for:
Calculating IPv4 Subnets and Hosts

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 could 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 slash eight. But if we wanted to cut that pizza into smaller pieces, we might have a subnet mask of a slash 24, or even a slash 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 eight bits would be one, and the remaining bits would be zero. 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 slash eight subnet. This means that the network bits would be those first eight bits of the address, and the host bits would be the last 24 bits of the address. Since this is a slash eight subnet mask, we are drawing our line after those first eight 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 eight. 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 eight 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 slash 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 two. For example, you can look at two to the first power is two, two to the second power is four, two to the third power is eight, 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 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 slash 24. If we perform our calculation in binary, we would write out all 24 of those bits as 1s, 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 slash 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 slash 26. If we were to write out that slash 26, you can see there are 26 ones. That leaves us with two ones in the last octet, and we have six zeros 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. 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 six 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 two bits left over as the subnet bits. 2 to the second power is 4. To calculate the host per subnet, we have six bits. So we take two to the sixth power and subtract two from there. That means we have 64 minus two, or 62. So for this IP address of 192.168.11.0 slash 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 slash 21. If we looked at this in binary, we would have 21 ones, which means we have eight in the first octet, eight in the second octet, and five ones in the third octet. Everything else, of course, would be zeros. 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 5th 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 2048 minus 2, or a total of 2046 devices. So for this IP address of 172.16.55.0 slash 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 this 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.