Subnet Mask Binary Calculator
Convert an IPv4 subnet mask between CIDR prefix length, dotted-decimal notation and 32-bit binary form. Check valid contiguous subnet masks and inspect every mask octet in decimal, hexadecimal and binary.
What Is a Subnet Mask?
A subnet mask is a 32-bit IPv4 value used to distinguish the network portion of an IPv4 address from the remaining host portion. In binary form, a valid subnet mask begins with a continuous sequence of 1 bits and ends with a continuous sequence of 0 bits.
For example, the common subnet mask 255.255.255.0 contains twenty-four leading 1 bits and eight trailing 0 bits. It can therefore also be written using CIDR notation as /24.
How the Subnet Mask Binary Calculator Works
This calculator accepts a CIDR prefix, dotted-decimal subnet mask or 32-bit binary subnet mask and converts it into the other standard representations.
The tool also checks whether a decimal or binary mask is valid. A correct IPv4 subnet mask cannot contain a 1 after the first 0 has appeared.
Invalid: 11111111.11111111.10111111.00000000
CIDR Prefix to Subnet Mask
CIDR notation expresses the number of leading network bits using a slash followed by a number from 0 through 32.
means: 24 network bits
8 host bits
The first 24 mask bits are set to 1 and the remaining 8 are set to 0:
Converting those four binary octets to decimal gives:
Subnet Mask to CIDR Prefix
To convert a valid subnet mask to CIDR notation, count the number of 1 bits in its binary representation.
Binary: 11111111.11111111.11111111.11000000
Number of 1 bits: 26
CIDR: /26
The remaining six bits are the host portion of the mask.
Subnet Mask Binary Values
Because valid subnet-mask bits must remain contiguous, an individual subnet-mask octet has only a small number of valid decimal values.
| Binary Octet | Decimal | Bits Set |
|---|---|---|
| 00000000 | 0 | 0 |
| 10000000 | 128 | 1 |
| 11000000 | 192 | 2 |
| 11100000 | 224 | 3 |
| 11110000 | 240 | 4 |
| 11111000 | 248 | 5 |
| 11111100 | 252 | 6 |
| 11111110 | 254 | 7 |
| 11111111 | 255 | 8 |
Common Subnet Masks in Binary
| CIDR | Decimal Mask | Binary Ending |
|---|---|---|
| /8 | 255.0.0.0 | 11111111.00000000.00000000.00000000 |
| /16 | 255.255.0.0 | 11111111.11111111.00000000.00000000 |
| /24 | 255.255.255.0 | 11111111.11111111.11111111.00000000 |
| /25 | 255.255.255.128 | 11111111.11111111.11111111.10000000 |
| /26 | 255.255.255.192 | 11111111.11111111.11111111.11000000 |
| /27 | 255.255.255.224 | 11111111.11111111.11111111.11100000 |
| /28 | 255.255.255.240 | 11111111.11111111.11111111.11110000 |
| /29 | 255.255.255.248 | 11111111.11111111.11111111.11111000 |
| /30 | 255.255.255.252 | 11111111.11111111.11111111.11111100 |
| /31 | 255.255.255.254 | 11111111.11111111.11111111.11111110 |
| /32 | 255.255.255.255 | 11111111.11111111.11111111.11111111 |
Why Subnet Masks Use Contiguous 1 Bits
CIDR subnet masks are defined by a prefix length. A prefix represents a continuous block of network bits beginning at the most-significant side of the address.
For that reason, a valid mask cannot switch from 1 to 0 and then back to 1 later in the bit pattern.
Invalid: 11111111 11101111 11110000 00000000
The calculator checks this rule when converting a user-entered decimal or binary mask.
Subnet Mask Octet Example
Consider the mask:
Its binary octets are:
255 = 11111111
248 = 11111000
0 = 00000000
Counting the set bits gives:
Therefore the CIDR prefix is:
What Are Network Bits and Host Bits?
The CIDR prefix length indicates how many of the 32 IPv4 mask positions belong to the network prefix. The remaining positions are host bits.
Network bits: 20
Host bits: 32 – 20 = 12
This calculator reports these bit counts but intentionally does not use them to calculate host capacity or subnet address ranges.
/24 Subnet Mask in Binary
A /24 subnet mask is one of the most commonly encountered IPv4 masks.
Decimal: 255.255.255.0
Binary: 11111111.11111111.11111111.00000000
Hex: FF FF FF 00
The first three complete octets are network bits, while the fourth octet contains eight host-bit positions.
/26 Subnet Mask in Binary
A /26 mask contains twenty-six network bits.
Binary: 11111111.11111111.11111111.11000000
Decimal: 255.255.255.192
Host bits: 6
The last octet 11000000 contains two network bits followed by six host bits.
/20 Subnet Mask Example
A /20 prefix crosses the third IPv4 octet instead of ending exactly on an octet boundary.
Binary: 11111111.11111111.11110000.00000000
Decimal: 255.255.240.0
This example demonstrates why knowing the binary subnet-mask pattern can be useful when learning or troubleshooting IPv4 networking.
Subnet Mask vs IPv4 Address
An IPv4 address and subnet mask are both 32-bit values, but they serve different purposes.
| Value | Main Purpose |
|---|---|
| IPv4 Address | Represents an IPv4 interface or endpoint address |
| Subnet Mask | Identifies the network-prefix positions within an IPv4 address |
That is why BinaryCon keeps the IPv4 Binary Calculator and Subnet Mask Binary Calculator as separate tools.
Subnet Mask vs CIDR Notation
CIDR notation and dotted-decimal subnet masks are two representations of the same prefix information.
255.255.255.0 = /24
255.255.255.240 = /28
CIDR is compact, while dotted-decimal notation makes the four IPv4 octets visible.
Subnet Mask Hexadecimal Representation
A subnet mask can also be displayed as four hexadecimal bytes. Each decimal octet maps directly to two hexadecimal digits.
Hex: FF FF FF 00
For a /26 mask:
Hex: FF FF FF C0
Hexadecimal representation can be useful when inspecting low-level networking data or packet structures.
Why Binary Subnet Masks Matter
Computers evaluate IPv4 addresses and masks at the binary level. Viewing the mask as 32 individual bits makes the relationship between CIDR prefixes and dotted-decimal notation easier to understand.
Binary masks are useful for networking education, certification study, router and firewall configuration review, packet analysis, troubleshooting and software development involving IP address processing.
Subnet Mask Validation
Not every four-octet value from 0 through 255 is a valid subnet mask. The bits must form one uninterrupted sequence of 1s followed by one uninterrupted sequence of 0s.
For example:
255.255.254.0 = valid
255.255.253.0 = invalid
The decimal value 253 is binary 11111101, which contains a 0 followed later by another 1. That breaks the contiguous-prefix rule.
Important Subnet Mask Notes
IPv4 masks contain exactly 32 bits.
CIDR prefix lengths range from /0 through /32.
A valid subnet mask contains contiguous 1 bits followed only by 0 bits.
Each decimal mask octet must be from 0 through 255.
Binary masks may be entered as four 8-bit groups or as one continuous 32-bit string.
This calculator converts and validates subnet-mask representations only.
It does not calculate network addresses, broadcast addresses, wildcard masks, subnet counts, usable-host ranges or total hosts.
For real network configuration, always verify the intended prefix with your network design or administrator.