Subnet mask to prefix length calculator
Convert a dotted IPv4 subnet mask to its CIDR prefix length and validate contiguous bits. Enter your values below to see the result and method.
inputs.
Related calculators and articles
Compare methods and explore more free tools in computer science.
How to use the Subnet mask to prefix length calculator
Convert a dotted IPv4 subnet mask to its CIDR prefix length and validate contiguous bits. Use the free tool above without creating an account.
What it calculates
Convert a dotted IPv4 subnet mask to its CIDR prefix length and validate contiguous bits. The output reflects the input definitions and conventions used by the formula, so keep formats and units consistent when comparing scenarios.
Inputs and units
Enter Subnet mask. Review the labels and example values before calculating.
- Subnet mask: enter a value in the unit shown; the browser checks the accepted format and range.
Formula and method
prefix = count of leading one bits in a contiguous mask
The calculator applies this relationship directly and keeps intermediate values unrounded for the displayed estimate.
Worked example
255.255.255.0 has 24 leading one bits, so its prefix length is /24.
How to interpret the result
Use the result to answer the specific sizing, encoding, performance, or representation question stated on this page. It is conditional on the chosen inputs; change one input at a time to see how the estimate responds.
Assumptions and limitations
Only contiguous masks are accepted. Non-contiguous bit patterns are invalid as ordinary CIDR subnet masks.
Frequently asked questions
What does the prefix length count?
The prefix length is the number of leading 1 bits in a contiguous 32-bit IPv4 subnet mask. For example, 255.255.255.0 contains 24 leading 1 bits and is /24.
Which masks are valid inputs?
A valid IPv4 subnet mask has contiguous 1 bits followed only by 0 bits. A mask such as 255.0.255.0 is not a valid prefix mask and should be rejected.
Does the prefix identify a complete subnet by itself?
No. The prefix length defines the mask size; combine it with an IPv4 address to identify a specific network and address range.
How do I use the Subnet mask to prefix length calculator?
Enter Subnet mask. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Subnet mask to prefix length?
255.255.255.0 has 24 leading one bits, so its prefix length is /24.
Read the calculation methodology and privacy policy.