Understanding the CIDR to subnet mask converter — concept and principle
This converter turns a CIDR prefix length (/0 to /32) into the equivalent dotted-decimal subnet mask, its wildcard mask, the total number of addresses in the block, the number of usable host addresses and the mask written out in binary. It is the quick reference you need when a router asks for "255.255.240.0" but your documentation says "/20", or when you need to know whether a block is big enough for a site.
How it is calculated
- Mask: a 32-bit value whose first n bits are 1 and the remaining 32 − n bits are 0. Each group of 8 bits becomes one decimal octet.
- Wildcard: the bitwise inverse of the mask, equal to 255.255.255.255 − mask, octet by octet.
- Total addresses: 2^(32 − n).
- Usable hosts: 2^(32 − n) − 2 for n ≤ 30; 2 for /31 (point-to-point, RFC 3021); 1 for /32.
- Binary mask: the same 32 bits shown in four groups of eight.
The only octet values a valid mask can contain are 0, 128, 192, 224, 240, 248, 252, 254 and 255, because the ones must be contiguous from the left.
The principle
CIDR replaced the old fixed class boundaries with a simple rule: the network part is whatever the first n bits are. The mask is just a compact way of writing n. Every bit you move from the network side to the host side doubles the block size, which is why /24 holds 256 addresses, /23 holds 512 and /20 holds 4,096. The two reserved addresses (all-zeros host part for the network, all-ones for broadcast) are why the usable count is two less than the total for ordinary subnets.
Worked example
- Input: /20.
- The first 16 bits fill two octets with 255. Four more bits remain in the third octet: 11110000 = 128 + 64 + 32 + 16 = 240. The last octet is 0.
- Mask: 255.255.240.0. Binary: 11111111.11111111.11110000.00000000.
- Wildcard: 255 − 240 = 15 and 255 − 0 = 255, so 0.0.15.255.
- Total addresses: 2^(32 − 20) = 2^12 = 4,096. Usable hosts: 4,096 − 2 = 4,094.
| Prefix /n | Subnet mask |
|---|---|
| 5 | 248.0.0.0 |
| 10 | 255.192.0.0 |
| 15 | 255.254.0.0 |
| 20 | 255.255.240.0 |
| 25 | 255.255.255.128 |
| 30 | 255.255.255.252 |
| 40 | 255.0.0.0 |
How to read the result
Each step down in prefix length doubles capacity: /30 = 2 hosts, /29 = 6, /28 = 14, /27 = 30, /26 = 62, /25 = 126, /24 = 254, /22 = 1,022, /20 = 4,094, /16 = 65,534. A /20 block covers 16 consecutive /24 networks, so its third octet must start at a multiple of 16. Choose the smallest block that holds your hosts plus growth room.
Common mistakes
- Writing a non-contiguous mask such as 255.255.0.255; it is not a valid subnet mask.
- Entering the wildcard where the device expects a subnet mask, or the reverse.
- Forgetting that the usable count excludes the network and broadcast addresses.
Frequently asked questions
What mask is /20?
255.255.240.0, with 4,096 addresses and 4,094 usable hosts.
How many /24 networks fit in a /20?
Sixteen, because 2^(24 − 20) = 16.
What is a wildcard mask used for?
Some ACL and OSPF syntax uses it: a 0 bit must match, a 1 bit is ignored.
Why does /0 have no usable host count meaning?
/0 (0.0.0.0/0) represents the whole IPv4 space and is used as the default route, not as a subnet you assign hosts in.
Sources: IETF RFC 4632, Classless Inter-domain Routing (CIDR) · IETF RFC 950, Internet Standard Subnetting Procedure