Netmask to CIDR
- Prefix
- /24
- Subnet mask
- 255.255.255.0
- Wildcard mask
- 0.0.0.255
- Total addresses
- 256
- Usable hosts
- 254
Calculated in your browser · nothing is looked up or uploaded
Converts a dotted-decimal subnet mask into its CIDR prefix length, and refuses a mask that is not a contiguous run of ones.
How to use the netmask to cidr
Counting the leading ones is the whole conversion, but the validation is the part worth having. A subnet mask must be an unbroken run of ones followed by an unbroken run of zeros — that is what makes the network/host split a single boundary rather than a scattered set of bits. 255.0.255.0 looks plausible and is not a valid mask, and equipment will reject it in a way that is not always clear about why.
The check used here is a neat one: invert the mask and add one. For a valid mask that always gives a power of two, because the inverted mask is a run of ones at the bottom and adding one carries all the way through. If the result has more than one bit set, the mask has a gap.
Non-contiguous masks were briefly legal in the very early internet and were removed precisely because they made routing lookups impossible to do efficiently — the longest-prefix match that every router depends on assumes a single boundary.
Questions
/24 — twenty-four leading ones.