Subnet Mask vs CIDR: Converting Between Two Representations
Subnet masks like 255.255.255.0 and CIDR prefix lengths like /24 are two ways to express the same information. Here's the complete conversion table and the binary math behind it.
Subnet masks and CIDR prefix lengths express the same underlying concept — the boundary between the network portion and the host portion of an IP address — in two different notations. Older networking equipment and documentation often uses subnet masks; modern configuration and cloud infrastructure use CIDR. Fluency in both, and the ability to convert quickly, is a core networking skill. See our subnet mask vs CIDR guide for deeper background.
The Relationship
A subnet mask is a 32-bit value where all network bits are 1 and all host bits are 0. The CIDR prefix length is simply a count of those leading 1 bits. 255.255.255.0 in binary is 24 ones followed by 8 zeros — hence /24. The two notations are completely interchangeable.
Key Conversions
/8=255.0.0.0— see /8 reference/16=255.255.0.0— see /16 reference/24=255.255.255.0— see /24 reference/25=255.255.255.128/26=255.255.255.192/27=255.255.255.224/28=255.255.255.240— see /28 reference/29=255.255.255.248/30=255.255.255.252— see /30 reference/32=255.255.255.255— see /32 reference
Converting Mask to Prefix: The Counting Method
Count the consecutive 1 bits from the left in the binary representation of the mask. 255.255.240.0 in binary is 11111111.11111111.11110000.00000000 — count 20 ones, giving /20. For the common masks, you can memorise the third-octet values: 128 → 1 bit set, 192 → 2 bits, 224 → 3 bits, 240 → 4 bits, 248 → 5 bits, 252 → 6 bits, 254 → 7 bits, 255 → 8 bits.
Converting Prefix to Mask: The Subtraction Method
For each octet, the mask value is either 255 (fully in the network portion), 0 (fully in the host portion), or the boundary value. For a /26: the first 26 bits are network bits. The first three octets (24 bits) are all 1s = 255. The remaining 2 bits in the fourth octet give us 11000000 in binary = 192. So /26 = 255.255.255.192. Use the CIDR calculator to verify any conversion instantly.