Sub topic 11
Special prefixes and reserved ranges
This chapter assumes you can compute a network address, a broadcast address, and usable hosts for a prefix. Some prefixes and address blocks break the usual "subtract two" rule or have a fixed meaning. You need to recognize them.
Prefixes at the edges: /31 and /32
The usual rule is that a subnet has 2^h addresses and 2^h − 2 usable hosts, because one address is the network address and one is the broadcast address. That rule fails at the long end of the prefix range.
| Prefix | Addresses | Usable hosts | Typical use |
|---|---|---|---|
| /30 | 4 | 2 | Older point-to-point links |
| /31 | 2 | 2 | Point-to-point links (RFC 3021) |
| /32 | 1 | 1 (the address itself) | A single host, loopback, or a host route |
A /30 wastes half its addresses on a link between two routers. RFC 3021 allows a /31 on point-to-point links. There is no broadcast on such a link, so both addresses are usable.
A /32 names exactly one address. You see it in host routes, in router loopback interfaces, and in firewall rules that match one machine.
import ipaddress
link30 = ipaddress.ip_network("10.0.0.0/30")
link31 = ipaddress.ip_network("10.0.0.0/31")
host32 = ipaddress.ip_network("10.0.0.5/32")
print(list(link30.hosts())) # [IPv4Address('10.0.0.1'), IPv4Address('10.0.0.2')]
print(list(link31.hosts())) # [IPv4Address('10.0.0.0'), IPv4Address('10.0.0.1')]
print(host32.num_addresses) # 1Private ranges (RFC 1918)
Three blocks are reserved for private networks. Internet routers do not forward them, so many organizations can reuse them. A device that has only a private address reaches the internet through NAT.
| Block | Range | Addresses |
|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 to 10.255.255.255 | 16,777,216 |
| 172.16.0.0/12 | 172.16.0.0 to 172.31.255.255 | 1,048,576 |
| 192.168.0.0/16 | 192.168.0.0 to 192.168.255.255 | 65,536 |
Other reserved blocks
- 127.0.0.0/8 is loopback. Traffic to 127.0.0.1 never leaves the host.
- 169.254.0.0/16 is link-local. A host that fails to get an address from DHCP often assigns itself one here.
- 0.0.0.0/0 is the default route. It matches every address, and its prefix length of 0 makes it the least specific route.
- 224.0.0.0/4 is multicast.
- 100.64.0.0/10 is shared address space that providers use for carrier-grade NAT.
Checking addresses in Python
The ipaddress module knows these ranges, so you do not need to memorize every boundary.
import ipaddress
for text in ["10.1.1.1", "172.31.255.1", "172.32.0.1", "127.0.0.1", "169.254.7.7", "8.8.8.8"]:
ip = ipaddress.ip_address(text)
print(text, ip.is_private, ip.is_loopback, ip.is_link_local)
# 10.1.1.1 True False False
# 172.31.255.1 True False False
# 172.32.0.1 False False False
# 127.0.0.1 True True False
# 169.254.7.7 True False True
# 8.8.8.8 False False FalseNote that is_private is also true for loopback and link-local addresses. It covers every reserved non-public range, not only RFC 1918. To test for RFC 1918 specifically, use ip in ipaddress.ip_network("172.16.0.0/12") and similar checks.
Common errors
- Subtracting 2 from a /31 and concluding it has zero hosts.
- Treating all of 172.x.x.x as private.
- Putting a private range in a design that must be reachable from the internet without NAT.
- Using the same RFC 1918 block at two sites you later connect. The overlapping addresses cause routing conflicts.
Exercise
A link between two routers needs addresses for exactly two devices, and you want to waste as little space as possible. Which prefix do you choose, and what are the two usable addresses if the block starts at 192.168.50.8?
Show answer
Choose /31. The block 192.168.50.8/31 contains 192.168.50.8 and 192.168.50.9, and both are usable because a /31 has no network or broadcast address (RFC 3021).