Subnet Mask vs. CIDR Notation
How to convert between subnet masks (255.255.255.0) and CIDR prefix lengths (/24) — a complete conversion table and the math behind it.
Two ways to say the same thing
A subnet mask and a CIDR prefix length convey identical information — just in different formats.
/24
255.255.255.0
11111111.11111111
11111111.00000000
A subnet mask uses dotted-decimal notation where each 255 in an octet means
all 8 bits are set to 1 (network bits), and 0 means all host bits.
The CIDR prefix just counts those 1 bits: /24
means 24 bits are set — 255.255.255.0.
Complete conversion table /0–/32
| CIDR | Subnet Mask | Wildcard | Usable Hosts | Common Use |
|---|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,294 | Default route |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,214 | Class A / 10.x.x.x |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,574 | 172.16.0.0/12 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,534 | VPC / campus |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,766 | Half /16 |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,382 | Quarter /16 |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,190 | Large segment |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,094 | AWS default subnet |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,046 | Building network |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,022 | Medium segment |
| /23 | 255.255.254.0 | 0.0.1.255 | 510 | Two /24s |
| /24 | 255.255.255.0 | 0.0.0.255 | 254 | Standard subnet |
| /25 | 255.255.255.128 | 0.0.0.127 | 126 | Half /24 |
| /26 | 255.255.255.192 | 0.0.0.63 | 62 | Quarter /24 |
| /27 | 255.255.255.224 | 0.0.0.31 | 30 | Small workgroup |
| /28 | 255.255.255.240 | 0.0.0.15 | 14 | AWS NAT/endpoint |
| /29 | 255.255.255.248 | 0.0.0.7 | 6 | Tiny cluster |
| /30 | 255.255.255.252 | 0.0.0.3 | 2 | P2P link |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | RFC 3021 P2P |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | Single host |
How to convert between them
CIDR → Subnet Mask
Count /prefix ones from the left in a 32-bit number:
For /26: 26 ones then 6 zeros = 11111111.11111111.11111111.11000000 = 255.255.255.192
Subnet Mask → CIDR
Count the 1 bits in the mask. 255.255.240.0 = 11111111.11111111.11110000.00000000 = 20 ones = /20