Sub topic 11
The three RFC 1918 private ranges
This chapter assumes you can read dotted-decimal addresses, know that a prefix such as /12 fixes the first 12 bits as the network part, and can count addresses in a block with powers of two. Python 3 is optional, but the examples use it.
What RFC 1918 defines
RFC 1918 is a 1996 standards-track document, "Address Allocation for Private Internets". It sets aside three blocks of IPv4 addresses that no organization owns. Anyone can use them inside their own network without asking a registry. It replaced RFC 1597, which defined the same three blocks.
Two rules make the blocks useful:
- Any number of networks can reuse the same private addresses, because the addresses are only meaningful inside each network.
- Routers on the public internet must not carry routes to these blocks. Internet providers normally filter them, so a packet with a private destination address is dropped before it travels far.
The blocks were created because public IPv4 addresses ran short. A host that only talks to other hosts inside a company does not need a globally unique address. It needs one that is unique inside that company.
The ranges
| Block | Prefix | First address | Last address | Addresses | Classful equivalent |
|---|---|---|---|---|---|
| 24-bit block | 10.0.0.0/8 | 10.0.0.0 | 10.255.255.255 | 16,777,216 | One class A network |
| 20-bit block | 172.16.0.0/12 | 172.16.0.0 | 172.31.255.255 | 1,048,576 | 16 contiguous class B networks |
| 16-bit block | 192.168.0.0/16 | 192.168.0.0 | 192.168.255.255 | 65,536 | 256 contiguous class C networks |
RFC 1918 names the blocks by how many host bits they leave free: 24, 20, and 16. A /8 leaves 32 − 8 = 24 host bits, a /12 leaves 20, and a /16 leaves 16.
The classful column explains the odd shape of the middle block. When the RFC was written, classes still shaped how people thought about address space. The authors reserved one class A, a run of class Bs, and a run of class Cs. Today you should treat each block as a plain CIDR prefix and ignore the class names. You can split any of them into subnets of any size, such as 10.4.0.0/22 or 192.168.10.128/25.
You can print the table from the standard library:
import ipaddress
for text in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"):
net = ipaddress.ip_network(text)
print(text, net.network_address, net.broadcast_address, net.num_addresses)The output is:
10.0.0.0/8 10.0.0.0 10.255.255.255 16777216
172.16.0.0/12 172.16.0.0 172.31.255.255 1048576
192.168.0.0/16 192.168.0.0 192.168.255.255 65536Why 172.16.0.0/12 ends at 172.31
The 10 and 192.168 blocks end on octet boundaries, so they are easy to read. The 172 block does not, and it causes the most mistakes.
A /12 fixes 12 bits. The first octet (8 bits) is 172. The remaining 4 bits come from the second octet. Those 4 bits are 0001, so the second octet has the form 0001xxxx, and the low four bits can be anything.
for second in (15, 16, 31, 32):
print(second, format(second, "08b"))The output is:
15 00001111
16 00010000
31 00011111
32 00100000Only 16 through 31 start with 0001. So 172.16.x.x through 172.31.x.x are private, while 172.15.x.x and 172.32.x.x are public addresses owned by other organizations.
Checking membership in code
The reliable way to test an address is to check it against the three networks. Do not match on string prefixes.
import ipaddress
RFC1918 = [
ipaddress.ip_network("10.0.0.0/8"),
ipaddress.ip_network("172.16.0.0/12"),
ipaddress.ip_network("192.168.0.0/16"),
]
def is_rfc1918(text):
address = ipaddress.ip_address(text)
return any(address in network for network in RFC1918)
print(is_rfc1918("10.20.30.40")) # True
print(is_rfc1918("172.31.255.254")) # True
print(is_rfc1918("172.32.0.1")) # False
print(is_rfc1918("8.8.8.8")) # FalsePython's ip_address(...).is_private is not a substitute. It also returns True for loopback (127.0.0.1), link-local (169.254.x.x), and other special-purpose ranges. Use the explicit list when the question is specifically "is this an RFC 1918 address?"
How the three blocks are chosen in practice
All three blocks work the same way technically. The choice is about size and about avoiding collisions.
- 10.0.0.0/8 suits large organizations and cloud networks. It has room for many subnets, for example 256 networks of
/16or 65,536 of/24. - 172.16.0.0/12 is a middle size. It is also the default for some container tools, for example Docker's default bridge network, which uses
172.17.0.0/16. - 192.168.0.0/16 is the usual choice for home routers and small offices. Many consumer routers default to
192.168.0.0/24or192.168.1.0/24.
The defaults matter more than the sizes. If every home router uses 192.168.1.0/24, then a laptop on a home network that connects through a VPN to an office using the same range has a problem, as the next section explains.
Private addresses and the internet
A private address is not routable on the internet. A host with 192.168.1.10 can reach the internet only if something rewrites its source address to a public one. That job belongs to network address translation (NAT), usually done by the home router or a corporate gateway. The chapter on NAT covers the mechanism. For now, the flow looks like this:
The address 203.0.113.5 here is from a documentation range, standing in for a real public address.
Traffic between two private hosts in the same network, or in networks connected by your own routers or a VPN, needs no translation. That is why private addressing works well inside organizations.
Pitfalls
Overlapping networks
Two networks that use the same private range cannot be joined without extra work. If a branch office and headquarters both use 10.1.0.0/16, a router cannot tell which 10.1.4.7 a packet is meant for. Overlap also happens partially, when one block sits inside another:
import ipaddress
office = ipaddress.ip_network("10.1.0.0/16")
vpn_peer = ipaddress.ip_network("10.1.128.0/17")
other = ipaddress.ip_network("10.2.0.0/16")
print(office.overlaps(vpn_peer)) # True
print(office.overlaps(other)) # FalseTypical situations where overlap bites:
- Merging two companies that both used
10.0.0.0/8heavily. - Peering two cloud virtual networks that were both created with the same default range.
- A remote worker whose home
192.168.1.0/24matches the office's192.168.1.0/24over a VPN.
The fixes are renumbering one side, which is slow but clean, or translating one side with NAT, which is quicker but makes addresses harder to reason about. The best prevention is to plan address space centrally and record every allocation, and to avoid the most common defaults (192.168.0.0/24, 192.168.1.0/24, 10.0.0.0/24) for anything that may later connect to another network.
Leaking private addresses
Private addresses can show up in places they should not: in logs shared with outsiders, in DNS records that resolve publicly, or in email headers. A public DNS name that answers with 10.x.x.x is almost always a mistake, and some resolvers refuse such answers to protect against DNS rebinding attacks.
Private is not secure
A private address hides nothing by itself. It only means the address is not routed on the internet. Any host that can reach your network, including an attacker who has compromised one machine, can reach those addresses. Use firewalls and access control for security.
Not the only non-public space
RFC 1918 is only one kind of non-public space. Loopback (127.0.0.0/8) and link-local (169.254.0.0/16) are separate special-purpose ranges. Carrier-grade NAT uses the shared range 100.64.0.0/10, which is also not RFC 1918. A "private address" filter built on three RFC 1918 networks will let these through, so decide deliberately which ranges you mean.
Summary table of decisions
| Question | Answer |
|---|---|
| Is `172.20.5.9` private? | Yes, because 20 is between 16 and 31. |
| Is `172.32.0.1` private? | No. It is public address space. |
| Is `192.169.1.1` private? | No. Only `192.168.x.x` is. |
| Is `10.255.255.255` private? | Yes, the last address of the 10/8 block. |
| Is `169.254.10.10` RFC 1918? | No. It is link-local. |
Exercise
What is the first and last address of 172.16.0.0/12, and how many addresses does it contain?
Show answer
The first address is 172.16.0.0 and the last is 172.31.255.255. A /12 leaves 32 − 12 = 20 host bits, so it holds 2^20 = 1,048,576 addresses. The second octet runs from 16 (00010000) to 31 (00011111), which is 16 values, and each value covers 65,536 addresses, giving 16 × 65,536 = 1,048,576.
Exercise
A company uses 10.0.0.0/16 at headquarters and a branch office uses 10.0.5.0/24. They want to connect the sites with a VPN. Is there a problem, and what would you do?
Show answer
Yes. 10.0.5.0/24 lies inside 10.0.0.0/16, so the two ranges overlap, and a router cannot tell whether a packet for 10.0.5.x belongs to headquarters or the branch. Renumber the branch to a non-overlapping block, such as 10.1.5.0/24, or translate one side with NAT. Renumbering is cleaner for the long term.
Exercise
Why is "address starts with 172." a wrong test for a private address, and what should you use instead?
Show answer
Only 172.16.0.0 through 172.31.255.255 is private. Addresses like 172.15.0.1 and 172.32.0.1 are public. Test membership in the networks 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16, for example with Python's ipaddress module as in is_rfc1918.