Sub topic 11
Special prefixes and reserved ranges
This chapter assumes you can find the network address, broadcast address, and usable host range of a CIDR block. It also assumes you know that usable hosts equal 2^h − 2 for h host bits. Some prefix lengths and address ranges break those rules or carry a fixed meaning. This chapter covers them.
Prefix lengths that break the usual rules
The "subtract two" rule reserves the first address (network) and the last address (broadcast) of every subnet. That rule assumes a subnet holds many hosts. At the extreme ends of the prefix range, it stops working.
| Prefix | Total addresses | Usable hosts | Typical use |
|---|---|---|---|
| /0 | 4,294,967,296 | not applicable | Default route (`0.0.0.0/0`) |
| /30 | 4 | 2 | Point-to-point link, traditional |
| /31 | 2 | 2 (RFC 3021) | Point-to-point link, no waste |
| /32 | 1 | 1 (single host) | Host route, loopback, ACL entry |
/32: exactly one address
A /32 has no host bits, so the prefix names one address. You see it in three places:
- A router's loopback interface, such as
10.255.0.1/32, which gives the router a stable identity. - A host route, which sends traffic for one destination to a specific next hop.
- A firewall or access-list entry that matches one machine.
There is no network or broadcast address to subtract, because the block is a single address.
/31: two addresses, both usable
With a /30, a link between two routers consumes four addresses and uses two. RFC 3021 changed this: on a point-to-point link, a /31 has no need for a broadcast address, because the link has only one possible peer. Both addresses are assigned to the two ends.
For 10.0.0.0/31, the addresses are 10.0.0.0 and 10.0.0.1. One router takes each. A router with many links saves half of its link addressing by using /31 instead of /30.
/0: the whole address space
A /0 has zero network bits, so every address matches it. As a route, 0.0.0.0/0 is the default route: "if nothing more specific matches, send it here." The next chapter on longest-prefix match explains why this works without conflicting with other routes.
Python and the special cases
Python's ipaddress module (recent versions, 3.8 and later) treats /31 and /32 as RFC 3021 and host-route cases:
import ipaddress
for text in ["10.0.0.0/31", "10.0.0.5/32", "10.0.0.0/30"]:
net = ipaddress.ip_network(text)
print(text, net.num_addresses, list(net.hosts()))
# 10.0.0.0/31 2 [IPv4Address('10.0.0.0'), IPv4Address('10.0.0.1')]
# 10.0.0.5/32 1 [IPv4Address('10.0.0.5')]
# 10.0.0.0/30 4 [IPv4Address('10.0.0.1'), IPv4Address('10.0.0.2')]Notice that hosts() returns both addresses of the /31 and the single address of the /32. For the /30 it removes the first and last addresses, as you would by hand.
Private address space (RFC 1918)
Three blocks are reserved for use inside organizations. Routers on the public internet do not forward them, so many networks can reuse the same addresses.
| Block | Range | Addresses | Notes |
|---|---|---|---|
| `10.0.0.0/8` | 10.0.0.0 to 10.255.255.255 | 16,777,216 | Large networks |
| `172.16.0.0/12` | 172.16.0.0 to 172.31.255.255 | 1,048,576 | Easy to misread |
| `192.168.0.0/16` | 192.168.0.0 to 192.168.255.255 | 65,536 | Home and small office |
The 172.16.0.0/12 block is the one people get wrong. The /12 means the first 12 bits are fixed. The second octet is 0001 xxxx in binary, which covers 16 through 31. So 172.31.5.9 is private, but 172.32.0.1 and 172.15.0.1 are public addresses.
To reach the internet from a private network, a device must pass through network address translation (NAT), which rewrites the private source address to a public one.
Overlap is the real problem
Private ranges are reused everywhere, so two networks you later connect often use the same block. Typical cases are a VPN between two offices that both use 192.168.1.0/24, or a company merger where both sides use 10.0.0.0/8. Overlapping subnets cannot be routed to each other without translation or renumbering. When you design a plan, pick less common blocks (for example, a /16 out of 10.0.0.0/8 at an unusual second octet) to reduce the chance of collision.
Other reserved ranges you will meet
| Block | Purpose |
|---|---|
| `0.0.0.0/8` | "This network." `0.0.0.0` alone means "unspecified" or "any" |
| `127.0.0.0/8` | Loopback. `127.0.0.1` is the local machine |
| `169.254.0.0/16` | Link-local. Self-assigned when DHCP fails |
| `100.64.0.0/10` | Shared address space for carrier-grade NAT (RFC 6598) |
| `192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24` | Documentation examples (TEST-NET-1, 2, 3) |
| `224.0.0.0/4` | Multicast |
| `240.0.0.0/4` | Reserved for future use |
| `255.255.255.255/32` | Limited broadcast, never forwarded by routers |
A few of these deserve a closer look:
- Loopback is a whole /8, not a single address. Any address from
127.0.0.1to127.255.255.254points back to the local host. - Link-local addresses appear when a host is set to use DHCP but gets no answer. Seeing
169.254.x.xon a machine is a quick sign that DHCP failed. - Shared address space (
100.64.0.0/10) is not RFC 1918 private space. Internet providers use it between customer equipment and their own NAT devices. Avoid using it inside your own network, because it may collide with a provider's addressing. - Documentation ranges are safe to put in examples and tutorials, because nobody can be assigned them. Prefer them over real addresses when you write documentation.
- Limited broadcast (
255.255.255.255) reaches every host on the local segment. It differs from a subnet's directed broadcast, such as192.168.10.63for192.168.10.0/26, which is the last address of that one subnet.
The following diagram shows a simple way to classify an address.
Classifying addresses in code
The ipaddress module has built-in properties for many of these ranges. They are useful for quick checks:
import ipaddress
for text in ["10.1.2.3", "172.31.255.254", "172.32.0.1",
"192.168.1.1", "127.0.0.1", "169.254.10.20",
"100.64.0.1", "8.8.8.8"]:
ip = ipaddress.ip_address(text)
print(f"{text:16} private={ip.is_private!s:5} global={ip.is_global}")
# 10.1.2.3 private=True global=False
# 172.31.255.254 private=True global=False
# 172.32.0.1 private=False global=True
# 192.168.1.1 private=True global=False
# 127.0.0.1 private=True global=False
# 169.254.10.20 private=True global=False
# 100.64.0.1 private=False global=False
# 8.8.8.8 private=False global=TrueTwo details matter. First, is_private is true for loopback and link-local addresses too, not only RFC 1918 space, so it is broader than "RFC 1918." Second, 100.64.0.1 is neither private nor global, which reflects its special status.
If you need strictly RFC 1918, test membership in the three blocks yourself:
import ipaddress
RFC1918 = [ipaddress.ip_network(n) for n in
("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")]
def is_rfc1918(text):
ip = ipaddress.ip_address(text)
return any(ip in net for net in RFC1918)
print(is_rfc1918("172.16.5.1")) # True
print(is_rfc1918("172.32.0.1")) # False
print(is_rfc1918("127.0.0.1")) # FalseCommon mistakes
- Treating all of 172.x.x.x as private. Only
172.16.0.0through172.31.255.255is. - Using /31 on a shared LAN. It works only for two devices on a point-to-point link.
- Subtracting two from a /31 or /32. A /31 gives two usable addresses under RFC 3021, and a /32 is a single address by definition.
- Using
100.64.0.0/10as ordinary private space. It can clash with your provider's carrier-grade NAT. - Ignoring overlap. Two private networks with the same block cannot be joined directly. Check for overlaps with
net.overlaps(other)before connecting them. - Confusing
0.0.0.0the address with0.0.0.0/0the route. The first means "unspecified" for a single host. The second matches every destination.
Exercise
A router has 40 point-to-point links to other routers. How many addresses do the links consume if you number each with a /30, and how many with a /31? How many addresses do you save?
Show answer
Each /30 uses 4 addresses, so 40 links use 160. Each /31 uses 2 addresses, so 40 links use 80. You save 80 addresses, which is half. Both ends of each /31 link are usable under RFC 3021, so no hosts are lost.
Exercise
Decide whether each address is in RFC 1918 private space: (a) 172.20.4.9, (b) 172.40.1.1, (c) 100.100.0.5, (d) 192.168.255.254.
Show answer
(a) Yes. The second octet 20 is between 16 and 31, so it is inside 172.16.0.0/12. (b) No. 40 is outside 16 to 31, so it is a public address. (c) No. It falls in 100.64.0.0/10, the shared carrier-grade NAT space, which is not RFC 1918. (d) Yes. It is inside 192.168.0.0/16.
Exercise
Two offices both use 192.168.1.0/24 and you need to connect them with a VPN. Why does this fail as is, and what are two ways to fix it?
Show answer
Each side believes the whole 192.168.1.0/24 range is local, so neither will send traffic for the other office's hosts across the VPN. Both sets of addresses overlap. You can renumber one office to a different block, or you can use NAT to translate one office's addresses to a non-overlapping range for traffic crossing the VPN. Renumbering is cleaner over the long term.