Skip to content

Guide

Converting IPv4 subnet masks between binary and decimal

A subnet mask is four separate binary-to-decimal conversions wearing a dotted-decimal costume.

By Published

A subnet mask like 255.255.255.0looks like four ordinary decimal numbers, but it’s really a 32-bit binary pattern split into four 8-bit groups (octets) and displayed as decimal for readability — the same “dotted-decimal” notation used for IPv4 addresses themselves. Converting between the two forms is four independent binary-to-decimal conversions, one per octet.

Breaking a mask into octets

255.255.255.0 splits into four groups — 255, 255, 255, 0 — each converted to an 8-bit binary value independently:

Decimal octetBinary (8 bits)
25511111111
25511111111
25511111111
000000000

So 255.255.255.0 is 11111111.11111111.11111111.00000000 — 24 ones followed by 8 zeros. That count of leading 1s (24) is exactly the number in the CIDR shorthand /24, which is why network engineers often write 192.168.1.0/24 instead of pairing an address with its full dotted-decimal mask.

Why masks are always contiguous 1s then 0s

Per RFC 950 and the CIDR convention in RFC 4632, a valid subnet mask must be all 1 bits from the left, then all 0 bits — never mixed, like 11110011. That structure is what makes the CIDR shorthand possible: since the 1s are always contiguous starting from the left, a single number (the count of leading 1s) fully describes the mask, and any decimal octet that doesn’t correspond to a contiguous run of binary 1s or 0s isn’t a legal subnet mask value at all.

Common masks, both forms

CIDRDotted decimalBinary (last relevant octet)
/8255.0.0.011111111.00000000...
/16255.255.0.0...11111111.00000000...
/24255.255.255.0...11111111.00000000
/25255.255.255.12810000000
/26255.255.255.19211000000
/30255.255.255.25211111100

The partial octets (128, 192, 252) are where the powers-of-two summing method actually matters — 192 is 128 + 64 (the top two bits set), which is 11000000. For quick one-off conversions of an unfamiliar octet, a binary to decimal converter is faster and less error-prone than working it out by hand mid-configuration.

Frequently asked questions

What is 255.255.255.0 in binary?
11111111.11111111.11111111.00000000 — each of the four decimal octets (255, 255, 255, 0) converts independently to an 8-bit binary value. 255 is eight 1s (11111111); 0 is eight 0s (00000000).
Why are subnet masks always made of contiguous 1s followed by contiguous 0s?
Per RFC 950 and modern CIDR practice (RFC 4632), a valid subnet mask must have all its 1 bits contiguous from the left, with all 0 bits contiguous after them — there's no valid mask like 11110011. This structure is what lets a mask be represented as a single CIDR number (like /24) instead of a full dotted-decimal value.
How do I convert a CIDR prefix like /24 to dotted decimal?
Write out 24 ones followed by 8 zeros (32 bits total for IPv4), split into four 8-bit groups, and convert each group to decimal: 11111111.11111111.11111111.00000000 → 255.255.255.0. Each full octet of 1s is 255; a partial octet needs the powers-of-two sum for whichever bits are set.
What does a subnet mask actually determine?
Which bits of an IP address identify the network versus the host. Where the mask has a 1, that bit position is part of the network address; where it has a 0, that bit is free to vary between devices on the same network (the host portion).

Sources & references

Authoritative references cited by this piece. Verified by Buğra Sözeri on the dates shown and re-checked at every deploy.

Related

More guides on this topic

Published September 25, 2026