Subnet Mask to CIDR Converter

Enter a dotted subnet mask to get its CIDR prefix length.

Result

/27
30 hosts
0.0.0.31

How it is calculated

The four octets of the dotted mask are written as 8-bit binary and joined into one 32-bit string. A valid subnet mask is a run of 1s followed by a run of 0s, and the CIDR prefix is the number of 1s: prefix = count of 1-bits. The usable host count is 2(32 − prefix) − 2, which reserves the network and broadcast addresses. The wildcard mask is each octet subtracted from 255, which is the bitwise inverse. The mask needs exactly four numbers from 0 to 255 separated by dots; surrounding spaces are ignored. Masks whose bits are not contiguous, such as 255.0.255.0, an inverted mask such as 0.0.0.255, a slash form such as /24, or a value over 255 give no result. For /31 the tool shows 2 usable hosts, because a point-to-point link between two routers uses both addresses (RFC 3021), and for /32 it shows 1, a single host address. IPv4 only.

Worked example

Take the mask 255.255.255.224. The last octet 224 is 11100000 in binary, so the full mask has 8 + 8 + 8 + 3 = 27 ones. The tool shows /27. That leaves 32 − 27 = 5 host bits, so 25 − 2 = 32 − 2 = 30 usable hosts. The wildcard is 255 − 255, 255 − 255, 255 − 255 and 255 − 224, giving 0.0.0.31. A /27 therefore splits a /24 network into eight blocks of 32 addresses.

Try this example →

Common mistakes

  • Typing the wildcard mask instead of the subnet mask. 0.0.0.255 has its 1s at the end, so it is rejected; the subnet mask for the same network is 255.255.255.0.
  • Entering the prefix itself, such as /24 or 24. This tool expects four dotted numbers, so a prefix gives no result.
  • Using a mask with a gap, like 255.255.0.255. Every 1-bit must come before every 0-bit; masks that break this are not valid subnet masks.
  • Counting all addresses as hosts. Out of the 32 addresses in a /27, two are reserved and 30 are usable, and the tool already subtracts them.
  • Applying the 2ⁿ − 2 rule by hand to /31 and /32: they are special cases with 2 and 1 usable addresses, which is what the tool shows.

Sources

About this calculator

A dotted-decimal subnet mask like 255.255.255.0 and its CIDR notation /24 describe the exact same thing: the mask, converted to binary, is a run of consecutive 1-bits followed by 0-bits, and the CIDR prefix is simply the count of those leading 1-bits. A /24 mask leaves 8 host bits, giving 256 total addresses and 254 usable host addresses after reserving the network and broadcast address.

Network engineers and system administrators convert between the two notations constantly when configuring routers, firewalls, and subnets, since older tools and documentation often use dotted masks while modern configs favor CIDR.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    For sizing, work from the number of devices. About 500 hosts need nine host bits, which means a /23, mask 255.255.254.0, with 510 usable addresses; type that mask to confirm the prefix and host count. If a mask your equipment shows gets rejected here, post it so others can see the pattern. Which mask formats confuse you most?

Popular calculators

All Calculators