tallge

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

PrefixNetmaskAddressesUsable hosts
/8255.0.0.016,777,21616,777,214
/12255.240.0.01,048,5761,048,574
/16255.255.0.065,53665,534
/20255.255.240.04,0964,094
/22255.255.252.01,0241,022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422 (point-to-point, RFC 3021)
/32255.255.255.25511 (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

RangePurpose
10.0.0.0/8private (RFC 1918)
172.16.0.0/12private (RFC 1918): 172.16.0.0 to 172.31.255.255
192.168.0.0/16private (RFC 1918)
100.64.0.0/10shared space for carrier-grade NAT (RFC 6598)
192.0.0.0/24IETF protocol assignments (RFC 6890)
127.0.0.0/8loopback; the whole /8, not only 127.0.0.1
169.254.0.0/16link-local, self-assigned when DHCP fails
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24documentation and examples
198.18.0.0/15benchmark testing
224.0.0.0/4multicast
240.0.0.0/4reserved
255.255.255.255/32limited broadcast
0.0.0.0/8"this network"; 0.0.0.0 as a listen address means all interfaces

IPv6 prefixes in use

PrefixTypical meaning
/32allocation to an ISP or a large organisation
/48one site; 65,536 subnets of /64
/56common delegation to a home or small office; 256 subnets
/64one subnet (LAN or VLAN); required for SLAAC
/127link between two routers (RFC 6164)
/128a single address, such as a loopback or a host route
RangePurpose
::1/128loopback
fe80::/10link-local; every interface has one
fc00::/7unique local addresses, in practice fd00::/8
2001:db8::/32, 3fff::/20documentation (RFC 3849, RFC 9637)
100::/64discard-only (RFC 6666)
ff00::/8multicast
::ffff:0:0/96IPv4-mapped addresses, such as ::ffff:192.0.2.1
2000::/3global 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.

Sources