Subnet Mask to CIDR Converter Calculator

Routers, firewalls, cloud consoles and operating systems all describe the same 32-bit value in different notations: /26, 255.255.255.192, 0.0.0.63, 0xFFFFFFC0. This converter moves between all of them in either direction and shows the block size and usable host count that go with each. It also rejects masks that are not legal — a subnet mask must be a run of 1 bits followed by a run of 0 bits, which is why 255.255.255.200 can never be a valid mask even though every octet is a number in range.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
What do you have?Pick the notation you are starting from; the calculator produces every other notation.A prefix length (/n)
Prefix length (/n)The number of leading 1 bits in the mask, from 0 to 32 — the value after the slash in 10.1.0.0/26.26 /
Subnet maskDotted decimal, as an OS or firewall shows it — for example 255.255.254.0.255.255.255.192

It returns

  • Prefix length — The count of leading 1 bits — the CIDR notation for this mask.
  • Dotted-decimal mask
  • Wildcard mask (ACL)
  • Binary mask
  • Hexadecimal mask
  • Block size (addresses)
  • Usable hosts per subnet

The formula

M=232232n
W=232n1

In plain text: mask = 2^32 − 2^(32−n); octet value = 256 − 2^(8 − bits in that octet)

  • MThe subnet mask as a 32-bit unsigned integer (—)
  • nPrefix length: the number of leading 1 bits (bits)
  • 32 − nHost bits, which are the trailing 0 bits of the mask (bits)

A valid mask is contiguous: every 1 bit precedes every 0 bit. That constraint is what makes the prefix length a complete description of the mask.

Updated Category IP Addressing & Subnetting Verified against published test cases Reading time 10 min

Why one mask has four different spellings

A subnet mask is a single 32-bit number. Everything else — the slash notation, the dotted decimal, the wildcard, the hex string — is a way of writing that number down, and which one you see depends only on which vendor's tool you are looking at. Cisco interface configuration wants dotted decimal. Cisco access lists want the wildcard. Linux, Windows and every cloud provider's VPC console want CIDR. Packet captures and some firewall exports show hex.

The number itself has a rigid shape: n ones followed by 32 − n zeros, and nothing else. That is why a prefix length is a complete description. There are only 33 legal masks, one for each value of n from 0 to 32, and each octet of a legal mask can only take one of nine values: 0, 128, 192, 224, 240, 248, 252, 254 and 255. Any other octet value means someone typed a digit wrong.

The rule exists because routing hardware matches prefixes by comparing a fixed number of leading bits. A mask with a gap in it — 255.255.255.200, binary 11001000 in the last octet — would describe a set of addresses that is not a contiguous range, which no longest-prefix-match lookup can represent. Wildcard masks in ACLs are allowed to have gaps, precisely because ACL matching is done bit by bit rather than by prefix length. That is the one real difference between the two notations, and it is worth remembering.

Converting in each direction

Prefix to mask. Write n ones, pad to 32 bits with zeros, then read the result eight bits at a time. For /26 that is 11111111.11111111.11111111.11000000, and the last octet, 11000000, is 128 + 64 = 192. The arithmetic shortcut avoids the binary entirely: in the octet where the mask breaks, the value is 256 minus the increment, and the increment is 2 raised to the number of host bits in that octet. A /26 leaves 6 host bits in the fourth octet, 26 = 64, and 256 − 64 = 192.

Mask to prefix. Count the 1 bits. Full octets of 255 contribute 8 each, so 255.255.255.192 gives 8 + 8 + 8 and then the partial octet. For the partial octet, subtract it from 256 to get the increment, and take the base-2 logarithm to get the host bits: 256 − 192 = 64, log264 = 6 host bits, so 8 − 6 = 2 network bits in that octet. Total 24 + 2 = 26.

Mask to wildcard. Subtract each octet from 255. 255.255.255.192 becomes 0.0.0.63. Equivalently, the wildcard is the block size minus one, which is why a /26 wildcard is 63 and a /22 wildcard is 1,023 written as 0.0.3.255.

To hexadecimal. Convert each octet to two hex digits and concatenate. 255 is FF, 192 is C0, so /26 is 0xFFFFFFC0. This is the form you see in tcpdump filters and in some vendor APIs.

Worked example: turning 255.255.248.0 into every other notation

A firewall reports an interface mask of 255.255.248.0 and you need the CIDR prefix, the wildcard and the host capacity.

  1. Count the full octets. The first two octets are 255, contributing 8 + 8 = 16 bits.
  2. Handle the partial octet. The third octet is 248. The increment is 256 − 248 = 8, and 8 = 23, so that octet has 3 host bits and therefore 8 − 3 = 5 network bits.
  3. Add them up. 16 + 5 + 0 = 21 network bits, so the mask is /21.
  4. Confirm in binary. 11111111.11111111.11111000.00000000 — twenty-one 1 bits followed by eleven 0 bits.
  5. Block size. 32 − 21 = 11 host bits, 211 = 2,048 addresses. In the third octet the increment is 8, so blocks start at .0.0, .8.0, .16.0 and so on.
  6. Usable hosts. 2,048 − 2 = 2,046, after removing the network number and the directed broadcast.
  7. Wildcard. 255 − 255 = 0, 255 − 255 = 0, 255 − 248 = 7, 255 − 0 = 255, giving 0.0.7.255. Check: block size 2,048 − 1 = 2,047 = 7 × 256 + 255. Correct.
  8. Hexadecimal. FF FF F8 00 → 0xFFFFF800.

Every one of those steps is reversible, which is the point of the tool: enter /21 instead and you get 255.255.248.0 back.

How to read the result

The block size is also the increment. This is the single most useful consequence of the conversion. A /26 has a block size of 64, so subnets of that size start at .0, .64, .128 and .192 in the fourth octet. A /21 has a block size of 2,048, which is 8 × 256, so subnets start every 8 in the third octet. Knowing the increment lets you place a boundary without a tool.

Usable hosts is block size minus two, except at the ends. A /31 has two usable addresses under RFC 3021 because point-to-point links need no broadcast, and a /32 has one because it is a single host route. Everywhere from /0 to /30 the subtraction applies.

Treat a rejected mask as a typo, not a limitation. When this calculator refuses a mask it is because the 1 bits are not contiguous. In practice that means a transposed digit — 255.255.255.240 typed as 255.255.255.204, or 252 typed as 225. The binary form shown in the error message makes the gap obvious.

The mask alone tells you nothing about which network you are on. It describes the shape of the block, not its position. To resolve an actual address to its network number and host range, use the IPv4 subnet calculator.

Complete CIDR prefix to subnet mask table

Every legal IPv4 mask, with its wildcard, block size and usable host count.
PrefixSubnet maskWildcard maskBlock sizeUsable hosts
/8255.0.0.00.255.255.25516,777,21616,777,214
/12255.240.0.00.15.255.2551,048,5761,048,574
/16255.255.0.00.0.255.25565,53665,534
/17255.255.128.00.0.127.25532,76832,766
/18255.255.192.00.0.63.25516,38416,382
/19255.255.224.00.0.31.2558,1928,190
/20255.255.240.00.0.15.2554,0964,094
/21255.255.248.00.0.7.2552,0482,046
/22255.255.252.00.0.3.2551,0241,022
/23255.255.254.00.0.1.255512510
/24255.255.255.00.0.0.255256254
/25255.255.255.1280.0.0.127128126
/26255.255.255.1920.0.0.636462
/27255.255.255.2240.0.0.313230
/28255.255.255.2400.0.0.151614
/29255.255.255.2480.0.0.786
/30255.255.255.2520.0.0.342
/31255.255.255.2540.0.0.122
/32255.255.255.2550.0.0.011

Wildcard = block size − 1. Usable = block size − 2 except at /31 (RFC 3021) and /32.

The nine-value trick

You never need to convert binary in your head. Memorise the sequence 128, 192, 224, 240, 248, 252, 254, 255 — each is the previous one plus the next halving of 128 — and note that they correspond to 1 through 8 network bits in that octet. Then a mask like 255.255.240.0 reads directly: two full octets is 16, and 240 is the fourth value in the sequence, so 4 more bits, giving /20.

Conversion mistakes that cost an outage

  • Putting a wildcard where a mask belongs. Configuring 0.0.0.63 on an interface, or 255.255.255.192 in an OSPF network statement, produces an adjacency that never forms and a route that never appears.
  • Reading 255.255.255.0 as /25. The count is of 1 bits, not of octets that are not 255. Three full octets is 24 bits, so 255.255.255.0 is /24.
  • Assuming a /24 is always 192.168.x.0. The mask fixes the block size, not the address. A /24 inside 10.0.0.0/8 is just as much a /24.
  • Typing a non-contiguous mask. 255.255.255.224 and 255.255.255.242 differ by one keystroke; only the first is legal. Any octet outside the nine legal values is a typo.
  • Confusing the mask with the network prefix in IPv6. IPv6 has no dotted-decimal mask notation at all — only prefix length — so a converter like this one has no IPv6 equivalent, and none is needed.
  • Forgetting that a /31 or /32 breaks the minus-two rule. Applying it blindly gives 0 and −1 usable hosts, which is where a lot of home-grown scripts fall over.

Where notation conversion fits in a design workflow

Conversion is the smallest of the three addressing tasks, and usually the last one. You start by deciding how many hosts a segment needs, which the hosts per subnet calculator turns into a prefix length. You then place that prefix inside a parent allocation and read off its network number, broadcast and host range with the IPv4 subnet calculator. Only when you go to configure the thing do you need the mask in whatever notation the device speaks — which is this page.

The historical reason for the two notations is worth one paragraph. Before 1993, IPv4 was classful: the first octet implied the mask, so 10.x.x.x was always a /8 and 192.168.x.x was always a /24. Masks were written in dotted decimal because they were an extension bolted onto that scheme by RFC 950. CIDR, defined in RFC 1519 and updated by RFC 4632, made the prefix length an explicit part of every route, and slash notation is simply the compact way to carry it. Dotted decimal survives because operating systems and interface configuration syntax never changed.

One practical note for cloud work: AWS, Azure and Google Cloud all use CIDR exclusively for VPC and subnet definitions, and all three reserve extra addresses beyond the standard two — typically the first few addresses of each subnet for their own gateway, DNS and future use. That reduces the usable count this page reports, so check your provider's documentation before sizing a subnet down to the last address. If those subnets host instances you are paying for by the hour, the cloud VM monthly cost calculator turns the instance plan into a monthly figure.

Frequently asked questions

What CIDR is 255.255.255.192?

/26. The first three octets contribute 24 bits, and 192 in binary is 11000000, contributing 2 more, for 26 network bits. A /26 has a block size of 64 addresses and 62 usable hosts, and its wildcard mask for access lists is 0.0.0.63.

How do I convert a subnet mask to CIDR in my head?

Count 8 for every octet of 255, then find the partial octet in the sequence 128, 192, 224, 240, 248, 252, 254 and add its position. For 255.255.240.0: two full octets is 16, and 240 is the fourth entry in the sequence, so 16 + 4 = /20. Trailing zero octets add nothing.

Why is 255.255.255.200 not a valid subnet mask?

Because its 1 bits are not contiguous. 200 in binary is 11001000, which has ones, then zeros, then ones again. A subnet mask must be an unbroken run of 1 bits followed by 0 bits so it can describe a single continuous address range. Only nine octet values are legal: 0, 128, 192, 224, 240, 248, 252, 254 and 255.

What is the difference between a subnet mask and a wildcard mask?

They are bitwise complements: subtract each mask octet from 255 to get the wildcard. A subnet mask goes on an interface and must be contiguous. A wildcard goes in a Cisco access list, OSPF network statement or route map, and may contain gaps, which lets it match patterns such as every even-numbered subnet. Using one where the other belongs fails silently.

What is /24 in decimal?

255.255.255.0. It is the most common mask in private networks: 24 network bits and 8 host bits, giving 256 addresses and 254 usable hosts. Its wildcard is 0.0.0.255 and its hexadecimal form is 0xFFFFFF00.

Does IPv6 use subnet masks?

No. IPv6 uses prefix length only, written as /64, /48 or /56, and there is no dotted or colon-separated mask notation. The concepts of network bits and host bits still apply, but the standard interface identifier is 64 bits, so almost every IPv6 LAN is a /64 regardless of how many hosts it holds.

How many usable hosts does each mask give?

Block size minus two, because the all-zeros host pattern names the network and the all-ones pattern is the directed broadcast. A /24 gives 254, a /26 gives 62, a /30 gives 2. The exceptions are /31, which gives 2 under RFC 3021 for point-to-point links, and /32, which gives 1 as a host route.

Why do cloud providers show fewer usable addresses than this calculator?

Because AWS, Azure and Google Cloud each reserve additional addresses in every subnet for their own gateway, DNS resolver and internal use, on top of the network number and broadcast. The reserved count is typically five per subnet. This page reports the protocol-level figure; check your provider's subnet documentation and subtract their reservations before you size a subnet tightly.

References