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 Buğra SözeriPublished
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 octet | Binary (8 bits) |
|---|---|
| 255 | 11111111 |
| 255 | 11111111 |
| 255 | 11111111 |
| 0 | 00000000 |
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
| CIDR | Dotted decimal | Binary (last relevant octet) |
|---|---|---|
| /8 | 255.0.0.0 | 11111111.00000000... |
| /16 | 255.255.0.0 | ...11111111.00000000... |
| /24 | 255.255.255.0 | ...11111111.00000000 |
| /25 | 255.255.255.128 | 10000000 |
| /26 | 255.255.255.192 | 11000000 |
| /30 | 255.255.255.252 | 11111100 |
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.
- IETF RFC 950 — Internet Standard Subnetting Procedure — The original RFC defining subnet masks for IPv4 addressing(as of )
- IETF RFC 4632 — Classless Inter-domain Routing (CIDR) — The CIDR notation (/24, /16, etc.) used as shorthand for subnet masks today(as of )
Related
More guides on this topic
- Password Entropy Explained: How It's Actually CalculatedThe log2(charset) × length formula behind every password strength meter, worked examples at real lengths, and why entropy isn't the whole story.
- How to Make a QR Code Menu for Your Restaurant TableA QR menu is a link to a web page, not a PDF trapped behind a code. How to build one that loads fast, updates instantly, and actually gets scanned at the table.
- Reading Timestamps in Log Files and JSON API ResponsesLog lines and JSON payloads rarely say which timestamp format they use. How to spot seconds vs. milliseconds at a glance and batch-convert a whole column.
- Static vs Dynamic QR Codes: Which One Do You Need?A static code's link is fixed forever; a dynamic code redirects through a URL you control and can edit or track. What each costs you and when to use which.
Published September 25, 2026