Calculating networks and hosts
In this chapter, you’ll learn how to calculate the size of IPv4 networks and how many IP addresses they can hold. This technique is called subnetting.
Subnetting lets you create multiple smaller IP networks from one larger network by extending the subnet mask (in other words, increasing the prefix length). Practically, that means you borrow host bits and turn them into network bits by changing bits in the subnet mask from 0 to 1. After you do that, the point where the 1s stop (and the 0s begin) becomes the new network/host boundary.
Calculating the amount of networks
Let’s walk through an example.
Say you have one IP network, 192.168.1.0/24, and you need to split it into two separate IP networks. You can do that by changing (extending) the original subnet mask.
The subnet mask /24 is written in CIDR notation.
What would be the dotted-decimal representation of this subnet mask?
255.255.255.0
To divide a network into multiple networks, you borrow host bits from the original subnet mask and convert them into network bits. The key question is: how many host bits do you need to borrow to create the number of networks you want?
You can calculate that with this formula:
This means to the power of “”, where “” is the number of host bits you borrow (and turn into network bits). The result is the number of networks you can create with the new subnet mask.
For example, if you borrow 1 host bit, then :
So, borrowing 1 host bit from a /24 (making it a /25) gives you 2 networks.
Next, let’s look at the host bits available in the original subnet mask. To see the bits clearly, convert the subnet mask to binary.
(Image 136)
Image Title - Subnet Mask 255.255.255.0 with the Binary bits underneath
Now, here’s what the subnet mask looks like after converting one host bit into a network bit:
(Image 137)
Image Title - Borrowing a Host bit from the 255.255.255.0 Subnet Mask
When you borrow a host bit, you extend the subnet mask, and the network/host boundary moves. Now look at the positional values in the 4th octet. That makes the new dotted-decimal subnet mask:
255.255.255.128
What is the new subnet mask in CIDR notation?
/25
Now that we have a new subnet mask, we also have a new network boundary. With the original /24, the network could accommodate 254 usable host addresses. With this new /25, let’s calculate how many usable host addresses each network can accommodate.
Calculating how many host addresses within a network
You can calculate how many usable host addresses a network can hold with this formula:
This is to the power of “”, minus , where “” is the number of host bits left in the subnet mask.
You subtract 2 because:
- the network address (the first address in the range) can’t be assigned to a host
- the broadcast address (the last address in the range) can’t be assigned to a host
With the subnet mask 255.255.255.128, you have 7 host bits left in the 4th octet (because you borrowed 1 of the original 8 host bits). Plug that into the formula:
So each /25 network has 126 usable (assignable) host addresses.
Now apply this /25 to the original network and list the resulting ranges.
Starting with the first network (192.168.1.0):
| Network Address | Assignable Range | Broadcast Address |
|---|---|---|
| 192.168.1.0/25 | 192.168.1.1 - 192.168.1.126 | 192.168.1.127 |
Since the previous network ended at 192.168.1.127, the next network must begin at 192.168.1.128. That becomes the network address for Network #2.
Network #2
| Network Address | Assignable Range | Broadcast Address |
|---|---|---|
| 192.168.1.128/25 | 192.168.1.129 - 192.168.1.254 | 192.168.1.255 |
Each network can accommodate 126 usable host addresses.
- Full range: 192.168.1.128 - 192.168.1.255
- Usable/assignable range: 192.168.1.129 - 192.168.1.254
- Broadcast address: 192.168.1.255
At this point, you can’t create another network from 192.168.1.0/24 using /25, because you’ve already used the entire 4th octet range. That’s why a subnet mask of 255.255.255.128 produces only 2 networks, and each of those networks supports 126 usable host addresses.
Practicing subnetting
Let’s try another example. What if you needed 4 networks?
Start with the original subnet mask 255.255.255.0 and use the networks formula. Borrowing 1 host bit isn’t enough:
Borrowing only 1 host bit gives you 2 networks, which is not enough.
Now try borrowing 2 host bits:
That works. You need to borrow 2 host bits to create 4 networks.
Next, determine the new subnet mask after borrowing 2 host bits, and then calculate how many usable host addresses fit in each network.
(Image 138)
Image Title - Borrowing two Host bits from the 255.255.255.0 Subnet Mask
The new subnet mask becomes 255.255.255.192 after adding up the positional values with “on” bits in the 4th octet.
What will the new subnet mask (or “prefix length”) be in CIDR notation?
/26
More subnetting examples
Now calculate how many usable host addresses each of these 4 networks can accommodate. Borrowing 2 host bits from the original 8 in the 4th octet leaves 6 host bits.
Plug that into the host formula:
So each of the 4 networks can hold 62 usable (assignable) host addresses. There are 64 total addresses per /26, but 2 are reserved (network and broadcast).
Here are the 4 networks created with this subnet mask:
| Network | Network Address | Assignable Range | Broadcast Address |
|---|---|---|---|
| 1 | 192.168.1.0/26 | 192.168.1.1 - 192.168.1.62 | 192.168.1.63 |
| 2 | 192.168.1.64/26 | 192.168.1.65 - 192.168.1.126 | 192.168.1.127 |
| 3 | 192.168.1.128/26 | 192.168.1.129 - 192.168.1.190 | 192.168.1.191 |
| 4 | 192.168.1.192/26 | 192.168.1.193 - 192.168.1.254 | 192.168.1.255 |
Let’s do one more example. What if you needed 5 networks?
Borrowing 1 host bit gives 2 networks, and borrowing 2 host bits gives 4 networks - still not enough. Try borrowing 3 host bits:
Borrowing 3 host bits gives you 8 networks. Even though you only need 5, that’s fine as long as you don’t end up short.
(Image 139)
Image Title - Borrowing three Host bits from the 255.255.255.0 Subnet Mask
The new subnet mask becomes 255.255.255.224, which is /27.
Now calculate usable host addresses per /27. Borrowing 3 host bits leaves 5 host bits:
So each /27 network supports 30 usable host addresses.
Here are all the networks:
| Network | Network Address | Assignable Range | Broadcast Address |
|---|---|---|---|
| 1 | 192.168.1.0/27 | 192.168.1.1 - 192.168.1.30 | 192.168.1.31 |
| 2 | 192.168.1.32/27 | 192.168.1.33 - 192.168.1.62 | 192.168.1.63 |
| 3 | 192.168.1.64/27 | 192.168.1.65 - 192.168.1.94 | 192.168.1.95 |
| 4 | 192.168.1.96/27 | 192.168.1.97 - 192.168.1.126 | 192.168.1.127 |
| 5 | 192.168.1.128/27 | 192.168.1.129 - 192.168.1.158 | 192.168.1.159 |
| 6 | 192.168.1.160/27 | 192.168.1.161 - 192.168.1.190 | 192.168.1.191 |
| 7 | 192.168.1.192/27 | 192.168.1.193 - 192.168.1.222 | 192.168.1.223 |
| 8 | 192.168.1.224/27 | 192.168.1.225 - 192.168.1.254 | 192.168.1.255 |