# IPv4 Addresses and Subnetting – CompTIA Network+ N10-006 – 1.8

The calculation of an IP subnet is a relatively straightforward process, and in this video you’ll learn how to use binary math to calculate the network address, broadcast address, and device addresses on an IP subnet.

<<** Previous:** Classless Inter-Domain Routing**Next:** APIPA >>

Many people are intimidated over the IP subnetting part of the Network+ exam. But now that you know about binary math, you’ll find that the process is relatively straightforward. And you should very easily be able to calculate all of these IP subnet values.

Let’s look at an IPv4 address. We’ve become very accustomed to seeing these. So I’ve put one IP address here at the top– 192.168.1.131. And just underneath this is the binary representation of that. You can see each one of these sections is an eight bit block.

We often refer to this as a byte or even an octet. That means that an IP version 4 address is 32 bits long, or four bytes in length. An IP version 4 address in each one of these blocks, because it is eight bits– that means that the values you can have here would range between 0 and 255. None of these numbers can exceed 255 because we’re dealing with eight bits in this single block.

Let’s now break down what an IP address really is. If you recall from our previous video, IP address consists of two parts. There is a network address and a host address associated with this. And to be able to break those two things apart, you not only need the IP address, but you also need the subnet mask.

So if we take this example of 192.168.1.0– that’s our network address– and the subnet mask that has been assigned to this network is 255.255.255.0. So the first thing we’ll do is write out both the network address and the subnet mask in binary. And if we do that you can see 192.168.1.0. And then the subnet mask, of course, is a contiguous set of ones. And there are 24 ones in this 255.255.255.0.

Now every place that there is a 1 in a subnet mask is the network address. Every place there is a 0 in the subnet mask is a host address. That means that the network address is masked by those ones. That’s where that subnet mask comes from. The client addresses are not masked by the ones. They are the zeroes here.

And I put the h for those host or client addresses. And because we’ve got eight separate bits that are listed for host addresses, if we do our calculations eight bits means there are 256 possible places that we could have in there. We always subtract two.

We subtract one number for the network address and one number for the broadcast address, which then leaves us with the maximum number of hosts that we can have on that subnet, which means in this case there would be 254 separate hosts on this particular subnet.

Every network is going to have a network or subnet address. And every network is going to have a broadcast address. And you can calculate the subnet address and the broadcast address by setting the bits in the host part of the mask. If you set all of the bits to 0 you can calculate the subnet address. And if you set all of the bits to 1 you can calculate the broadcast address.

So let’s look at this scenario, 192.168.1.165, which is a host on a network. And this host has a subnet mask of 255.255.255.0. And the first thing we’ll do is to calculate out what this network address might be. So we’re going to have all of our host bits set to 0. And we’re going to calculate out what that number is.

And we do this by performing a function called a bitwise and. That means we’re going to look at the differences between these bits and make a determination of what those differences are. If the two bits are 1 and 1 that means that we bring down a 1 into the answer that we have.

If it’s anything else– if it’s a 0 and a 0, if it’s a 1 and a 0, if it’s a 0 and a 1– then we put a 0 down at the bottom. The only time we would put a 1 is if we have a 1 in both sections of these. And you can see a 1 and a 1 will bring down the 1. Here’s another pair of ones. Any time that’s different, like a 0 and a 1, it’s a 0. And any time there’s a 0 and a 0 it’s also 0.

So if we list out all the bits in our IP address and all of the bits in our subnet mask and we perform this bitwise and, we’re left with this final number. And that is going to be our network address or our subnet address. And if we calculate that back to decimal, it’s 192.168.1.0. That is our subnet, or network, address.

To determine what the broadcast is for a particular network you change all of those host values to a 1 and you perform the same calculation. So if we have the same number with ones in the host place, we get 192.168.1.255. And that is the broadcast address for this particular subnet.

So let’s recap what we’ve determined. We know that we have an IP address of 192.168.1.165. And it has been assigned a subnet mask of 255.255.255.0 by the network administrator. We performed our calculations. And we determined that the subnet address was 192.168.1.0. And the broadcast address is 192.168.1.255.

The number of devices that we can have on this network is every number that’s between the subnet address and the broadcast address. And we can calculate this easily by looking at how many bits are available for the host. We have eight of those. That means that we have 256 total numbers.

We’re going to take out the subnet address and the broadcast address– that’s the minus 2– which means we have a total number of hosts that can be used on this network of 254. And if we were going to write this out that means we would look at 192.168.1.1– that’s the first host after the subnet address– all the way through 192.168.1.254. That’s the address that’s just before the broadcast address, giving us a total of 254 addresses.

Let’s perform the exact same calculation again. Because it is exactly the same calculation every single time, even if the IP address is differently and the subnet mask is differently. It’s the same process. We’re going to convert to binary. We’re going to perform the bitwise and. We’re going to change the zeroes to ones and determine what the subnet address is and what the broadcast address is.

Let’s look at this address. 10.11.12.13 is the device on a network. And it has been assigned a subnet mask of 255.255.0.0. If you were to write this out in CIDR block notation it means that we would have 10.11.12.13/16, because there are 16 bits that are set in the subnet mask.

We would know that visually if we took these IP address and the subnet mask and wrote it out in binary. So if we look at 10.11.12.13, this is the binary representation. And if we look at 255.255.0.0, this is the binary representation. Every place there is a 1 in the subnet mask is the network address. And everything that is after that are the hosts that are on this particular subnet.

So let’s perform that bitwise and function and bring down every place there are two ones we’re going to have a 1. Every place there is anything else we’re going to have a 0. And now we have this network address and the host values that we have associated with this network.

That means if we write this out in decimal now, 10.11.0.0 is our subnet address. And if we look at changing all of these zeroes to ones, we would get the broadcast address. And if we calculate that, it’s 10.11.255.255. That means the entire range that we would have would be the first number after the network address, all the way through the last number, just before the broadcast address.

So let’s summarize these values. If we take that number we were looking at, 10.11.12.13 on the subnet mask of 255.255.0.0, we’ve got a subnet address of 10.11.0.0 and a broadcast address of 10.11.255.255. That means we have 16 bits set aside for a host, which means that the total number, if we were to calculate in binary all ones for that 16 bits, that means gives us a total of 65,536.

We subtract the network address and the broadcast address to give us a total number of available hosts on this network of 65,534. The first address on the subnet is 10.11.0.1. That’s the first address after the subnet address. And the last possible host that we can have on this subnet is 10.11.255.254, which is the last host just before the broadcast address.

As you can tell, it’s a relatively rote process to determine what the network address is, the broadcast address might be, and the host range of a particular subnet. But how do you know what size to make the subnet mask for what your requirements might be? And these particular values are often dictated by whoever’s providing you with the IP address to start with.

Usually the ISP or a central body in your organization has to find a particular addressing scheme. They’ve determined what the IP address ranges are and what the subnet masks are that they’ll use inside of the organization. And they may just hand you a particular value and say you can subnet this however you’d like. So you have to make a decision about how many networks we need and how many hosts are going to be on each one of those individual networks.

Here’s one of these scenarios. Let’s say in this organization that you’re at a remote site and you’re in charge of addressing your network at this remote site. The main office has already determined what their IP addresses are. And they’re simply going to hand you a block of IP addresses. And they’re going to tell you your assignment is 192.168.1.0. We’ve assigned you a subnet mask of 255.255.255.0. They might also write this down in CIDR block notation, so it would look like 192.168.1.0/24.

Now, you know that you have four networks at your remote location. And each network has about 40 devices on each one of these networks. But the main office has only given you a single network address. That means that you’re going to have to subnet it.

You will have to split up this address into smaller pieces so that you can fit the requirements for your particular site. If we were to write out a table of all of the subnet masks now for the IP address that we have been provided, we can list it out this way.

Here’s the subnet mask 255.255.255.0. That’s the one that was assigned by our corporate office. And we can see the binary representation of that subnet mask, the /24 mask. They’ve given you one network. And you can fit 254 hosts per network.

But we can start splitting this off in different ways. If we were to subnet this down to 255.255.255.128, which means we’re just going to use one extra bit into that last octet, this would be a /25 subnet. That means that we could have two separate networks. And we could have 126 hosts on each individual subnet.

Of course, in our scenario we have more than two networks. So let’s go to the next one where we have 255.255.255.192. So now we’re using two additional bits into that last octet. If we were to write this out in CIDR block notation this would be the /26 subnet.

In this particular scenario we’ve got two extra bits that we’ve assigned here now for network. So we have a total of four networks that we can have and 62 hosts per network. That particular scheme seems to fit our particular requirements. We had four networks. And we had 40 hosts per network. Well, this would give us the four networks. But it would give us 62 hosts per network. There’s a little bit more there than what we need.

So let’s look at what the next step down might be. If we were to look at the 255.255.255.224 network, which means we’re using three more bits into that last octet, or /27, that would give us eight networks. That would certainly give us more than we needed.

But notice that the hosts per network would be 30. And we have 40 devices per network. So if we were going to subnet out that single address they gave us we would subnet it with a /26, giving us four networks and 62 hosts per network.

Let’s now look at this address in a binary form to really break out what we just did. Here is our IP address 192.168.1.0, our subnet mask of 255.255.255.192. Here is the IP address of the network that we were given. And here is the subnet mask. And I’ve broken this out into colors. So we can see what we change with this subnet mask.

We were given the subnet 255.255.255.0. So I took the original subnet and made it blue. We subnetted further. And that additional subnet we use two additional bits. And I’ve colored those purple. And then we have the host bits that are now left over after performing our particular subnet. And if we look at that we decided on the 255.255.255.192. Here’s the binary representation. The /26 network is what that is. That will give us four networks. And it will give us 62 hosts per network.

Because we have been assigned a subnet we can’t change any of those values that we were given in that original subnet mask. So that blue value here, the blue bits, will never change. The only ones that we can change are the purple ones. Those are the additional subnets that we use.

And because we subnetted two additional bits we can turn on and off those bits to give us four separate subnets, a 00, 01, 10, and 11. And if we were to calculate out this particular subnet, 00, and if we had all of those host bits as set also to 0, we would get a subnet with a dot 0.

If we had one set to 01 and all zeros it would be a 64 network. We would have a 128 network. And if both bits were set to 1 it would be a 192 network. And if we were to look at the number of hosts available we have these six bits left for the host. That gives us a total number of hosts of 64 per network. Of course, we don’t use the subnet or the broadcast, which means we have a total of 62 hosts that we can have on each individual subnet.

If we were to summarize everything, we could write out every single one of these subnets now in binary and perform the calculations. So we have this 192.168.1.0 network. We have the subnet mask of 255.255.255.192. There’s our numbers there at the top.

Now we can just start calculating. Let’s set our subnet mask in purple here to 00 and perform the binary calculation, which gives us the first network of 192.168.1.0, because they’re all zeroes here. And of course, if we change this to have all ones in the host location, we can calculate the broadcast address. And if we calculate this in binary it’s 192.168.1.63, which is 00, 11, 11, 11.

Now of course, our first host is going to be one above the network address. So that’s going to be 192.168.1.1. And the maximum host, the highest number host, is going to be just one under the broadcast address, or 192.168.1.62. And I put the entire binary down so we can reference that as well.

Now if we change the 00 to 01 we can perform the same calculation for the second subnet. If we change it to a 10, same calculation again– and of course a 11– and get exactly the same calculation again. There’s no other ways that we can change those two bits. Those are the four networks that we get. And the second network is 192.168.1.64. We have a 192.168.1.128, and finally a 192.168.1.192.

We can now put all of these numbers in place. And we’ll assign each one of these router interfaces one of those IP addresses. So we have 192.168.1.0, 1.64, 1.128, and 1.192. These all go to these separate networks. And now we have four separate networks. And we can put up to 62 different devices on each one of these individual networks.

The rest of the network sees the original subnet address. All of the routing still continues to work normally, except now locally on our local router we’ve defined what the individual subnets might be. And by the time that traffic gets here, this router will know exactly where to send that traffic.

**Category**: CompTIA Network+ N10-006