Home / Network tools / Subnet mask to CIDR

Subnet Mask to CIDR Converter

Enter a subnet mask or wildcard mask and get the CIDR prefix. Or enter how many hosts you need and get the smallest block that fits.

Details

All IPv4 prefixes

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.

Frequently asked questions

How do I convert a subnet mask to CIDR?

Count the ones in the binary form of the mask. 255.255.255.0 has 24 ones, so it is /24.

What is 255.255.255.128 in CIDR?

/25. The last group, 128, adds one more 1 bit to the 24 in the first three groups.

Why is 255.0.255.0 rejected?

A valid subnet mask has all its ones first and then all its zeros. This one has a one after a zero.

How do I choose a subnet size for my hosts?

Add 2 to the number of hosts, round up to a power of 2, and use the matching prefix. The Hosts needed option does this for you.