From mask to prefix
To convert a subnet mask to CIDR notation, count the 1 bits when the mask is written in binary. The mask 255.255.255.0 has 24 ones, so it is /24. The mask 255.255.255.192 has 26 ones (24 plus the two in 192), so it is /26.
255.255.255.192
11111111.11111111.11111111.11000000
26 ones = /26
What makes a mask valid
A subnet mask is a run of ones followed by a run of zeros, with no gaps. 255.255.255.0 and 255.255.240.0 are valid. 255.0.255.0 is not, because a 1 comes after a 0, and the tool will say so. The valid values for one group are 0, 128, 192, 224, 240, 248, 252, 254 and 255.
Wildcard masks
Choose Wildcard mask if you have the inverse form, such as 0.0.0.255. The tool inverts it and gives /24.
Finding a prefix for a number of hosts
Choose Hosts needed and enter how many devices must fit in the subnet. The tool adds the two reserved addresses and rounds up to the next power of 2.
- 50 hosts need 52 addresses, so 64, which is a /26 with 62 usable hosts.
- 500 hosts need 502 addresses, so 512, which is a /23 with 510 usable hosts.
Leave some room to grow. A subnet that is exactly full is hard to extend without renumbering.
Reference table
The table under the converter lists all IPv4 prefixes with their masks and sizes.
The reverse conversion is on the CIDR to subnet mask page. For a complete breakdown of any block, use the CIDR calculator.