Opscraft
IP addressing & subnetting · Lesson 4 of 9 · 3 min read

CIDR notation and subnet masks

Prefix lengths

/n means the first n bits are the network. Host bits = 32 − n.

  • Total addresses = 2^(32−n)
  • Usable hosts (traditional networking) = 2^(32−n) − 2 (subtract the network address and the broadcast address)
  • Exceptions: /31 (point-to-point links, 2 usable, RFC 3021) and /32 (a single host route).
Enlarge diagram/24256 addresses/25128 addresses128 addresses/2664 addresses64 addresses64 addresses64 addresses/273232323232323232Usable hosts = addresses − 2 (network and broadcast); in AWS, addresses − 5.
Figure 1. Every step down in prefix length halves the block. Two /25s make a /24, four /26s make a /24, and so on.
Swipe sideways to see all of it, or tap to open it full screen.

The reference table

Prefix Mask Addresses Usable Block size (interesting octet)
/8 255.0.0.0 16,777,216 16,777,214 —
/12 255.240.0.0 1,048,576 1,048,574 16 (2nd octet)
/16 255.255.0.0 65,536 65,534 —
/17 255.255.128.0 32,768 32,766 128 (3rd)
/18 255.255.192.0 16,384 16,382 64 (3rd)
/19 255.255.224.0 8,192 8,190 32 (3rd)
/20 255.255.240.0 4,096 4,094 16 (3rd)
/21 255.255.248.0 2,048 2,046 8 (3rd)
/22 255.255.252.0 1,024 1,022 4 (3rd)
/23 255.255.254.0 512 510 2 (3rd)
/24 255.255.255.0 256 254 1 (3rd) / 256 (4th)
/25 255.255.255.128 128 126 128 (4th)
/26 255.255.255.192 64 62 64
/27 255.255.255.224 32 30 32
/28 255.255.255.240 16 14 16
/29 255.255.255.248 8 6 8
/30 255.255.255.252 4 2 4
/32 255.255.255.255 1 1 (host route) —

Quick anchors: each step down in prefix halves the size; a /24 is 256 addresses; /16 contains 256 /24s; /20 = 16 /24s; /22 = 4 /24s.

Wildcard masks

Some ACL syntaxes (Cisco, some firewalls) use the inverse of the mask: /24 → 0.0.0.255, /26 → 0.0.0.63. Compute as 255 − each mask octet.