Sub topic 11
Planning subnets: /48 to /64
This chapter assumes you know CIDR prefix notation, can convert between binary and hexadecimal, and know how IPv6 addresses split into a prefix and an interface identifier. It covers how an organization turns one /48 allocation into many /64 subnets, and what mistakes to avoid.
The three-part split
Most sites receive a /48 from their provider or registry. Host networks use /64 subnets. The 16 bits between those two lengths are the subnet ID, which you control.
For 2001:db8:abcd:0042::/64:
2001:db8:abcdis the 48-bit site prefix.0042is the subnet ID, which is the fourth group.- The remaining 64 bits are the interface identifier, which hosts generate themselves.
The subnet ID is a full 16-bit group, so one group of hexadecimal digits gives you the whole subnet number. That makes plans easy to read. You never do the bit-borrowing arithmetic that IPv4 requires.
How many subnets you get
A /48 leaves 64 − 48 = 16 bits for subnets, so it holds 2^16 = 65,536 subnets of /64. Each /64 holds 2^64 addresses. The ipaddress module can count and list them:
import ipaddress
from itertools import islice
site = ipaddress.ip_network("2001:db8:abcd::/48")
print(2 ** (64 - site.prefixlen)) # 65536 possible /64 subnets
for subnet in islice(site.subnets(new_prefix=64), 3):
print(subnet)
# 2001:db8:abcd::/64
# 2001:db8:abcd:1::/64
# 2001:db8:abcd:2::/64Note the islice. Without it, the loop would produce all 65,536 subnets.
Why /64 is the standard host subnet
Use a /64 for every network that has ordinary hosts, even if it will hold only five of them. Several mechanisms assume a 64-bit interface identifier:
- SLAAC forms addresses by combining a 64-bit prefix with a 64-bit identifier. It does not work on a longer prefix.
- Router Advertisements announce the on-link prefix, and hosts expect a /64.
- Several other features, such as Secure Neighbor Discovery and the recommended address-generation methods, also assume the 64-bit split.
Wasting addresses is not a concern. The space is so large that conserving it stops being a goal. The goal is a plan that is simple to read and easy to extend.
Choosing prefix lengths by context
| Prefix | Typical use | Notes |
|---|---|---|
| /32 | Large provider or organization allocation | Contains 65,536 /48 sites |
| /48 | One site, such as a campus or office | Contains 65,536 /64 subnets |
| /56 | Small site or home customer | Contains 256 /64 subnets |
| /64 | Any LAN with hosts | Required for SLAAC |
| /127 | Router-to-router point-to-point link | Avoids ping-pong between peers (RFC 6164) |
| /128 | One host or a router loopback | A single address |
A /56 for a home gives a household 256 networks. Some providers delegate a /60 or even a single /64, which restricts what a customer can build. If you have a choice, ask for at least a /56.
Designing a plan
You have 16 bits to spend, so give them structure. Three common approaches:
- Sequential. Number subnets 0, 1, 2 as you create them. This is simple, but the numbers carry no meaning.
- Function-based. Reserve ranges for roles, for example
0010to001ffor servers and0020to002ffor staff. - Hierarchical. Split the subnet ID into fields, for example the first hex digit for a building or region and the remaining three for the network within it. Each region then owns a /52 and can be summarized as one route.
Hierarchical plans pay off because routing tables stay small. A router can advertise a single /52 for an entire region instead of 4,096 separate /64 routes.
Align the divisions on hexadecimal digit boundaries (/52, /56, /60, /64). Each hex digit is 4 bits, so a boundary at a multiple of 4 means the divisions appear as whole digits in the written address and you can read them by eye. A /50 or /53 forces you to split a digit in binary.
import ipaddress
site = ipaddress.ip_network("2001:db8:abcd::/48")
regions = list(site.subnets(prefixlen_diff=4)) # sixteen /52 networks
print(len(regions))
print(regions[0]) # 2001:db8:abcd::/52
print(regions[1]) # 2001:db8:abcd:1000::/52
print(regions[15]) # 2001:db8:abcd:f000::/52Each /52 contains 2^12 = 4,096 /64 subnets.
You can also assign subnets from a role table by writing the subnet ID into bits 49 to 64:
import ipaddress
site = ipaddress.ip_network("2001:db8:abcd::/48")
plan = {"servers": 0x10, "staff": 0x20, "guest": 0x30, "management": 0xF0}
for name, subnet_id in plan.items():
base = int(site.network_address) | (subnet_id << 64)
subnet = ipaddress.IPv6Network((base, 64))
assert subnet.subnet_of(site)
print(name, subnet)
# servers 2001:db8:abcd:10::/64
# staff 2001:db8:abcd:20::/64
# guest 2001:db8:abcd:30::/64
# management 2001:db8:abcd:f0::/64The shift by 64 moves the subnet ID past the 64-bit interface identifier. The assert guards against an ID that does not fit in 16 bits. An ID larger than 0xFFFF would set bits in the site prefix, which is wrong, and the assertion would fail.
Edge cases and common errors
- Subnetting a LAN longer than /64. A /80 or /112 on a host network breaks SLAAC and some neighbor discovery security features. Keep host networks at /64.
- /127 versus /64 on links. A /64 on a router-to-router link works, but it exposes a very large address space to scanning and neighbor cache exhaustion. A /127 limits that. Some devices do not support it, so check your equipment. You can also assign a /64 to the link and configure only a /127 or /126 from it, which keeps the numbering regular.
- Forgetting to document. A plan nobody can read gets abandoned. Keep a table of subnet ID, role, VLAN, and owner.
- Mixing up leading zeros.
2001:db8:abcd:10::/64and2001:db8:abcd:0010::/64are the same subnet. Subnet ID0x10is decimal 16. Choose a convention (hex IDs, zeros omitted) and keep to it. - Using the wrong prefix in a copy. When you reuse a plan at a second site, replace the site prefix and keep the subnet IDs. This works only if the plan stores the subnet ID separately from the prefix.
- Forgetting that the /48 is not yours forever. Provider-assigned prefixes can change. Do not hard-code them in configuration that must outlive a renumbering. Using the relative subnet IDs makes renumbering a find-and-replace job on one prefix.
Exercise
A site has the prefix 2001:db8:5000::/48. You use the first hexadecimal digit of the subnet ID to identify one of 16 buildings. (a) What prefix length does each building receive, and how many /64 subnets does it contain? (b) What is the prefix of building 0xA?
Show answer
(a) The first hex digit is 4 bits, so each building gets a /52 (48 + 4). A /52 leaves 64 − 52 = 12 bits for subnets, so it contains 2^12 = 4,096 /64 subnets. (b) Building 0xA starts at subnet ID 0xA000, so its prefix is 2001:db8:5000:a000::/52.
Exercise
Why should you use a /64 for a small office LAN with only four hosts instead of a /120?
Show answer
SLAAC needs a 64-bit prefix and a 64-bit interface identifier, and other features assume the same split. A /120 would break SLAAC and cause problems with neighbor discovery features. Address space is not scarce, so the saving is meaningless.