Skip to main content
IP Range CalculatorPRO
Masks, Wildcards & ACLInstant Client-Side Tool

Subnet Mask to CIDR Converter

Find prefix length from contiguous masks.

Subnet Mask to CIDR Converter: inputs and results

Enter an IP address, CIDR prefix, or range. Then check its first and last address below.

Quick presets:

Calculated Boundaries & ParametersReady

Network Address192.168.1.0
Broadcast Address192.168.1.255
First Usable Host192.168.1.1
Last Usable Host192.168.1.254
Subnet Mask255.255.255.0
Wildcard Mask0.0.0.255
Total Addresses256
Usable Host Range254

How Subnet Mask to CIDR Converter Works?

This tool works by confirming that the mask is contiguous and then counting its 1 bits. The count is the CIDR prefix length.

  1. Enter a dotted mask

    Type a mask such as 255.255.252.0.

  2. Check each octet value

    Every octet must be one of 9 values: 0, 128, 192, 224, 240, 248, 252, 254, or 255.

  3. Check contiguity

    An octet below 255 must be followed only by 0 octets.

  4. Count the 1 bits

    255 (8) + 255 (8) + 252 (6) + 0 (0) = 22 → /22.

Subnet Mask to CIDR Converter Formula

The formula is p = 32 − log2(2^32 − Mask), which equals the number of 1 bits in a contiguous mask.

Bit count

p = Σ popcount(octet)

Counts the 1 bits.

Integer form

p = 32 − log2(2^32 − M)

M is the mask as an integer.

Octet lookup

128→1, 192→2, 224→3, 240→4, 248→5, 252→6, 254→7, 255→8

Bits contributed by each octet value.

Worked example: 255.255.252.0

255 → 8 bits
255 → 8 bits
252 → 11111100 → 6 bits
0   → 0 bits
CIDR = /22

Subnet Mask to CIDR Converter Conversion Table

The table maps 16 dotted masks, where the 3rd or 4th octet holds each of the 8 partial values, to their CIDR prefix.

Subnet MaskPartial OctetPartial Octet BinaryCIDR
255.255.128.012810000000/17
255.255.192.019211000000/18
255.255.224.022411100000/19
255.255.240.024011110000/20
255.255.248.024811111000/21
255.255.252.025211111100/22
255.255.254.025411111110/23
255.255.255.025511111111/24
255.255.255.12812810000000/25
255.255.255.19219211000000/26
255.255.255.22422411100000/27
255.255.255.24024011110000/28
255.255.255.24824811111000/29
255.255.255.25225211111100/30
255.255.255.25425411111110/31
255.255.255.25525511111111/32

What is Subnet Mask to CIDR Converter?

The Subnet Mask to CIDR Converter is a tool that turns a dotted-decimal IPv4 subnet mask into its CIDR prefix length. 255.255.252.0 becomes /22.

Prefix notation is shorter and fits directly after an address, as in 10.0.0.0/22. Cloud platforms, Linux ip commands, and routing tables use it everywhere. The converter turns masks copied from older devices into that format.

The converter accepts contiguous masks only. Non-contiguous masks such as 255.255.0.255 have no CIDR equivalent, and the converter flags them as invalid.

What are the uses of Subnet Mask to CIDR Converter?

There are 4 main uses of the Subnet Mask to CIDR Converter, including migrations, cloud entries, and log analysis.

  • Migrating firewall objects

    Objects stored with dotted masks become CIDR entries on the new platform.

  • Entering cloud network ranges

    AWS, Azure, and Google Cloud consoles accept CIDR only.

  • Reading Linux route tables

    Comparing route -n mask output with ip route CIDR output requires conversion.

  • Shortening documentation

    Design tables use /22 instead of 255.255.252.0 to save space.