Sub topic 9
Splitting a network into equal subnets
This chapter assumes you can convert between binary and decimal. It also assumes you know what a prefix length and a subnet mask are, and how to find the network and broadcast addresses of a block.
The idea: borrow host bits
A subnet is a smaller network carved out of a larger block. To make one, you move the boundary between network bits and host bits to the right. The bits that change sides are the borrowed bits. Each borrowed bit doubles the number of subnets and halves the size of each one.
- Number of subnets = 2^(borrowed bits)
- New prefix length = old prefix length + borrowed bits
- Addresses per subnet = 2^(32 − new prefix)
- Usable hosts per subnet = addresses per subnet − 2
Worked example: four subnets from a /24
Split 192.168.10.0/24 into four equal subnets.
- Four subnets need 2 borrowed bits, because 2^2 = 4.
- The new prefix is /24 + 2 = /26, which is mask 255.255.255.192.
- The block size is 256 − 192 = 64 in the last octet.
- The subnets start at 0 and step by 64.
| Subnet | Network | Usable range | Broadcast |
|---|---|---|---|
| 1 | 192.168.10.0/26 | .1 to .62 | 192.168.10.63 |
| 2 | 192.168.10.64/26 | .65 to .126 | 192.168.10.127 |
| 3 | 192.168.10.128/26 | .129 to .190 | 192.168.10.191 |
| 4 | 192.168.10.192/26 | .193 to .254 | 192.168.10.255 |
Each broadcast address is the next network address minus 1. Each subnet has 64 addresses and 62 usable hosts.
Choosing how many bits to borrow
For a /24, the options look like this:
| Borrowed bits | Prefix | Subnets | Block size | Usable hosts |
|---|---|---|---|---|
| 1 | /25 | 2 | 128 | 126 |
| 2 | /26 | 4 | 64 | 62 |
| 3 | /27 | 8 | 32 | 30 |
| 4 | /28 | 16 | 16 | 14 |
If you need 6 subnets, you must borrow 3 bits, because 2^2 = 4 is too few. You get 8 subnets and two go unused. Always round up.
The block size works in any octet
When the new prefix falls in the third octet, the block size applies to that octet. Split 10.0.0.0/16 into 6 subnets. Borrow 3 bits to get /19, which is mask 255.255.224.0. The block size is 256 − 224 = 32 in the third octet. The subnets are 10.0.0.0, 10.0.32.0, 10.0.64.0, and so on up to 10.0.224.0, all with /19. Each has 2^13 − 2 = 8190 usable hosts.
Generating the list with Python
The ipaddress module does the same arithmetic. subnets(new_prefix=...) yields the equal subnets in order.
import ipaddress
net = ipaddress.ip_network("192.168.10.0/24")
print(net.netmask) # 255.255.255.0
print(net.num_addresses) # 256
for sub in net.subnets(new_prefix=26):
print(sub, sub.network_address, sub.broadcast_address)
# 192.168.10.0/26 192.168.10.0 192.168.10.63
# 192.168.10.64/26 192.168.10.64 192.168.10.127
# 192.168.10.128/26 192.168.10.128 192.168.10.191
# 192.168.10.192/26 192.168.10.192 192.168.10.255Common errors
- Borrowing too few bits. Needing 5 subnets and borrowing 2 bits gives only 4.
- Forgetting the −2. A /26 holds 64 addresses but only 62 hosts, because the network and broadcast addresses are not assignable (the exceptions are covered in a later chapter).
- Starting a subnet off the boundary. Every network address must be a multiple of the block size. 192.168.10.32/26 is not a valid subnet, because it sits inside the first block.
- Applying the block size to the wrong octet. Find the octet where the mask is neither 255 nor 0. That is the octet that steps by the block size.
Exercise
Split 172.16.0.0/16 into 16 equal subnets. What is the new prefix, the block size, the second subnet, and the broadcast address of the last subnet?
Show answer
16 subnets need 4 borrowed bits, so the prefix is /20 (mask 255.255.240.0). The block size is 256 − 240 = 16 in the third octet. The second subnet is 172.16.16.0/20. The last subnet is 172.16.240.0/20, and its broadcast address is 172.16.255.255.