Convert between subnet masks and CIDR prefix lengths in either direction.
A subnet mask's CIDR prefix length equals the count of consecutive 1-bits starting from the most significant bit. Counting the 1-bits in a valid mask (e.g. 255.255.255.0 = 11111111.11111111.11111111.00000000 → 24 ones) gives the prefix directly, since a legitimate subnet mask always has all its 1-bits contiguous at the start.
Prefix from mask
prefix = count of leading 1-bits in the mask
255.255.255.0 has 24 leading 1-bits, so it is a /24.
A standard subnet mask must have all its 1-bits together at the start, followed by all 0-bits. If they're not contiguous, the value isn't a valid subnet mask and has no direct CIDR equivalent — it may be a wildcard mask instead.
This tool converts a subnet mask to its CIDR prefix length. The wildcard mask calculator instead inverts a subnet mask to produce the wildcard (ACL/OSPF) form — a different, complementary conversion.