Sub topic 12
Private address ranges
This chapter assumes you can convert between binary and dotted-decimal, read CIDR prefix notation such as /12, and know that a router forwards packets by matching destination addresses against prefixes. NAT itself is the next chapter. Here you learn which addresses it hides.
Why private ranges exist
IPv4 has about 4.3 billion addresses, and every host on the public Internet needs a unique one. Most networks do not need that. A laptop that only talks to a printer and a gateway does not need a globally unique address.
RFC 1918 sets aside three blocks that anyone may use inside their own network. No one owns them, so thousands of organisations reuse the same addresses at once. The price is that these addresses are not reachable from outside. Internet routers do not carry routes for them, and ISPs normally filter packets that use them as source or destination.
The three RFC 1918 blocks
| Block | Range | Mask | Addresses | Classful view |
|---|---|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 to 10.255.255.255 | 255.0.0.0 | 16,777,216 | 1 class A network |
| 172.16.0.0/12 | 172.16.0.0 to 172.31.255.255 | 255.240.0.0 | 1,048,576 | 16 class B networks |
| 192.168.0.0/16 | 192.168.0.0 to 192.168.255.255 | 255.255.0.0 | 65,536 | 256 class C networks |
The middle block is the one exam questions target. A /12 fixes the first 12 bits: the whole first octet (172) plus the top 4 bits of the second octet. Those four bits are 0001, so the second octet is 0001xxxx, which is 16 to 31. That is why 172.15.x.x and 172.32.x.x are public addresses, not private ones.
The address counts follow from the host bits: 2^24, 2^20 and 2^16. The mask 255.240.0.0 comes from 240 = 11110000 in binary, which is 4 more network bits after the 8 of the first octet.
Checking membership in code
The check is a prefix match, the same one a router performs.
import ipaddress
RFC1918 = [ipaddress.ip_network(p) for p in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")]
def is_rfc1918(addr):
ip = ipaddress.ip_address(addr)
return any(ip in net for net in RFC1918)
for net in RFC1918:
print(net, net.netmask, net.num_addresses)
for a in ["10.200.1.1", "172.15.255.255", "172.16.0.1", "172.31.255.254",
"172.32.0.1", "192.168.100.5", "192.169.0.1", "8.8.8.8"]:
print(a, is_rfc1918(a))The output lists the three blocks with their masks and sizes. Then 10.200.1.1, 172.16.0.1, 172.31.255.254 and 192.168.100.5 print True. The other four addresses print False. 172.15.255.255 and 172.32.0.1 each sit one step outside the /12.
Other special-purpose ranges
Some non-public addresses are not RFC 1918 and are not used for NAT inside a home or office network.
- 127.0.0.0/8 is loopback. Packets to it never leave the host.
- 169.254.0.0/16 is link-local. A host that fails to get a DHCP address often assigns itself one from this block.
- 100.64.0.0/10 is shared address space for carrier-grade NAT. ISPs use it between their customers and their own NAT devices.
import ipaddress
for a in ["127.0.0.1", "169.254.1.1", "100.64.0.1"]:
ip = ipaddress.ip_address(a)
print(a, ip.is_private, ip.is_global)Python's is_private is broader than RFC 1918, so 127.0.0.1 and 169.254.1.1 print True False. The address 100.64.0.1 prints False False: it is neither private nor global. If a question asks specifically about the three RFC 1918 blocks, test those blocks directly, as is_rfc1918 does above.
How private addresses are handled
A host with a private address can talk to other hosts in the same network directly. To reach the Internet, its packets must pass through a device that rewrites the source address to a public one. That is NAT, covered in the next chapter.
Common errors and edge cases
- Memorising 172.16.0.0 to 172.255.255.255. The block stops at 172.31.255.255. Check the second octet against 16 to 31.
- Calling 192.168.0.0/16 a single class C. Classfully it is 256 class C networks. Under CIDR it is one /16 that you can subnet freely.
- Overlapping address plans. If two sites both use 10.0.0.0/24 and you join them by VPN, routers cannot tell the two networks apart. Plan non-overlapping subnets before connecting networks.
- Leaking private routes. A private prefix advertised to the Internet is filtered by most providers. It also breaks reachability, because the destination is ambiguous.
- Assuming private means secure. Private addressing blocks inbound connections as a side effect of NAT. It is not a firewall.
- Sizing by habit. A large organisation can run out of 192.168.0.0/16. The 10.0.0.0/8 block is the usual choice when you need many subnets, and VLSM lets you carve it up efficiently.
Exercise
Which of these addresses is NOT in an RFC 1918 private block: 172.20.4.9, 172.32.0.5, 10.255.255.255, 192.168.200.1? Give the reason for your answer, and state how many addresses the 172.16.0.0/12 block holds.
Show answer
172.32.0.5 is not private. The 172 block fixes the top 4 bits of the second octet as 0001, so the second octet must be 16 to 31, and 32 is outside that range. The others are private: 172.20.4.9 has second octet 20, 10.255.255.255 is the last address of 10.0.0.0/8, and 192.168.200.1 is inside 192.168.0.0/16. The block 172.16.0.0/12 has 32 - 12 = 20 host bits, so it holds 2^20 = 1,048,576 addresses.
Exercise
A company wants 1,000 subnets of 200 hosts each using only RFC 1918 space and a single block. Which block must it use, and what prefix length should each subnet have?
Show answer
Each subnet needs at least 202 addresses including network and broadcast, so 8 host bits are needed (2^8 = 256, with 254 usable). That gives a /24 per subnet. 1,000 subnets of /24 need 1,000 x 256 = 256,000 addresses. 192.168.0.0/16 has only 65,536 addresses, and 172.16.0.0/12 has 1,048,576, which is enough, but its 16 class B-sized parts are better used as /24 subnets inside the /12 (4,096 of them). Either 172.16.0.0/12 or 10.0.0.0/8 works. 10.0.0.0/8 leaves the most room to grow. 192.168.0.0/16 is too small.