Subnet Mask Converter

Convert a CIDR prefix to a dotted-decimal mask and back, with the binary form and host bits.

What does this calculator do?

A subnet mask and a CIDR prefix say exactly the same thing in two notations: how many leading bits of the address belong to the network. This converter moves between them and also shows the binary mask, the wildcard mask, the host-bit count and the total addresses in the block. The conversion is exact — no rounding is involved. A valid mask is a single unbroken run of 1-bits followed by 0-bits, so a value such as 255.0.255.0 is rejected with a specific message rather than converted into a meaningless prefix. Everything is computed in your browser from the values you type. Nothing is looked up on the network — there is no ping, no DNS query, no WHOIS and no geolocation.

Formula

The prefix is simply the number of leading 1-bits in the mask.

prefix = count of leading 1-bits in the mask
mask   = 32 bits: prefix ones, then (32 − prefix) zeros
hostBits = 32 − prefix
totalAddresses = 2^hostBits

How to use it

Choose whether you are starting from a prefix or from a dotted-decimal mask; the form shows only the matching input. Masks must be written in full dotted-decimal form, for example 255.255.255.192, and must contain contiguous 1-bits. The result panel shows both notations side by side plus the binary mask, which makes the bit boundary easy to see.

Worked example

Mask 255.255.255.192 converts to /26: the binary mask is 11111111.11111111.11111111.11000000, which is 26 leading 1-bits. Host bits = 6, so the block holds 2⁶ = 64 addresses, and the wildcard mask is 0.0.0.63.

Formula version1.0.0
Formulaprefix = count of leading 1-bits in the mask mask = 32 bits: prefix ones, then (32 − prefix) zeros hostBits = 32 − prefix totalAddresses = 2^hostBits

Frequently asked questions

Why is 255.0.255.0 rejected?

A subnet mask must be a contiguous run of 1-bits followed by 0-bits. 255.0.255.0 turns the 1-bits back on after a gap, so it has no equivalent CIDR prefix and no router will accept it as a mask.

What does the binary mask show me?

It shows exactly where the network/host boundary falls inside the octets. For /26 the boundary is two bits into the fourth octet, which is why the blocks step by 64.

Are 255.255.255.255 and /32 valid?

Yes. /32 is a single host address, commonly used for loopback interfaces, host routes and firewall rules that match exactly one address.

Sources

Related calculators

Last updated: 2026-08-10 · v1.0.0 · Report an error