Reference / CIDR and subnet sizes
CIDR prefixes, subnet masks and address ranges
A prefix length says how many leading bits of an address identify the network. The remaining bits number the hosts.
IPv4 prefix table
| Prefix | Netmask | Addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /12 | 255.240.0.0 | 1,048,576 | 1,048,574 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /22 | 255.255.252.0 | 1,024 | 1,022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (point-to-point, RFC 3021) |
| /32 | 255.255.255.255 | 1 | 1 (single host) |
Addresses: 2^(32 - prefix). Usable hosts: that number minus the network and broadcast addresses, except for /31 and /32.
Doing it by hand
Find the octet where the prefix ends and the block size there: 256 minus the mask octet. For /26 the mask octet is 192 and the block size 64, so the networks in the last octet start at 0, 64, 128 and 192. The address 192.168.10.77/26 falls in the block starting at 64:
network 192.168.10.64
first 192.168.10.65
last 192.168.10.126
broadcast 192.168.10.127
Two prefixes can be merged into one only if they are adjacent and the lower one starts on a boundary of the larger size. 10.0.0.0/24 and 10.0.1.0/24 merge into 10.0.0.0/23; 10.0.1.0/24 and 10.0.2.0/24 do not.
Special IPv4 ranges
| Range | Purpose |
|---|---|
10.0.0.0/8 | private (RFC 1918) |
172.16.0.0/12 | private (RFC 1918): 172.16.0.0 to 172.31.255.255 |
192.168.0.0/16 | private (RFC 1918) |
100.64.0.0/10 | shared space for carrier-grade NAT (RFC 6598) |
192.0.0.0/24 | IETF protocol assignments (RFC 6890) |
127.0.0.0/8 | loopback; the whole /8, not only 127.0.0.1 |
169.254.0.0/16 | link-local, self-assigned when DHCP fails |
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 | documentation and examples |
198.18.0.0/15 | benchmark testing |
224.0.0.0/4 | multicast |
240.0.0.0/4 | reserved |
255.255.255.255/32 | limited broadcast |
0.0.0.0/8 | "this network"; 0.0.0.0 as a listen address means all interfaces |
IPv6 prefixes in use
| Prefix | Typical meaning |
|---|---|
| /32 | allocation to an ISP or a large organisation |
| /48 | one site; 65,536 subnets of /64 |
| /56 | common delegation to a home or small office; 256 subnets |
| /64 | one subnet (LAN or VLAN); required for SLAAC |
| /127 | link between two routers (RFC 6164) |
| /128 | a single address, such as a loopback or a host route |
| Range | Purpose |
|---|---|
::1/128 | loopback |
fe80::/10 | link-local; every interface has one |
fc00::/7 | unique local addresses, in practice fd00::/8 |
2001:db8::/32, 3fff::/20 | documentation (RFC 3849, RFC 9637) |
100::/64 | discard-only (RFC 6666) |
ff00::/8 | multicast |
::ffff:0:0/96 | IPv4-mapped addresses, such as ::ffff:192.0.2.1 |
2000::/3 | global unicast |
Writing IPv6 addresses
An address is eight groups of four hex digits. Leading zeros in a group may be dropped, and one run of all-zero groups may be replaced by ::, once per address. RFC 5952 fixes a canonical form so that the same address is always written the same way: lowercase, no leading zeros, :: for the longest run of two or more zero groups, the first one if two runs tie.
2001:0db8:0000:0000:0000:ff00:0042:8329 full
2001:db8:0:0:0:ff00:42:8329 leading zeros dropped
2001:db8::ff00:42:8329 canonical
In URLs an IPv6 address goes in brackets so the port can be told apart: [2001:db8::1]:8443.