IPv4 Subnet Mask Binary

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.

CIDR to Mask Mask to CIDR Binary Mask 32 Bits IPv4 Networking
Subnet Mask Conversion CIDR / Decimal / Binary
Choose the subnet-mask format you already know.
Enter a CIDR prefix length from 0 through 32.
A valid IPv4 subnet mask contains contiguous 1 bits from the left followed only by 0 bits. For example, /24 equals 11111111.11111111.11111111.00000000.
Subnet Mask Result
CIDR Prefix
Subnet Mask
Network Bits
Host Bits
Total Bits 32
Mask Hex
Full-One Octets
Boundary Octet
32-Bit Binary Subnet Mask

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.

Valid: 11111111.11111111.11111111.00000000

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.

/24

means: 24 network bits
8 host bits

The first 24 mask bits are set to 1 and the remaining 8 are set to 0:

11111111.11111111.11111111.00000000

Converting those four binary octets to decimal gives:

255.255.255.0

Subnet Mask to CIDR Prefix

To convert a valid subnet mask to CIDR notation, count the number of 1 bits in its binary representation.

255.255.255.192

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.

Valid: 11111111 11111111 11110000 00000000

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:

255.255.248.0

Its binary octets are:

255 = 11111111
255 = 11111111
248 = 11111000
0 = 00000000

Counting the set bits gives:

8 + 8 + 5 + 0 = 21

Therefore the CIDR prefix is:

/21

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.

For /20:

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.

CIDR: /24

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.

CIDR: /26

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.

Prefix: /20

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.0.0 = /16

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.

255.255.255.0

Hex: FF FF FF 00

For a /26 mask:

255.255.255.192

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.255.0 = valid

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

Important: this calculator handles IPv4 subnet masks only.

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.

Subnet Mask Binary Calculator FAQs

What does the Subnet Mask Binary Calculator do?
It converts IPv4 subnet masks between CIDR prefix notation, dotted-decimal notation and 32-bit binary notation.
What is 255.255.255.0 in binary?
255.255.255.0 is 11111111.11111111.11111111.00000000 in binary.
What CIDR prefix is 255.255.255.0?
It contains twenty-four leading 1 bits, so its CIDR prefix is /24.
What is a /26 subnet mask?
A /26 subnet mask is 255.255.255.192, or 11111111.11111111.11111111.11000000 in binary.
What is a /20 subnet mask?
A /20 subnet mask is 255.255.240.0.
How do I convert a subnet mask to CIDR?
Convert the subnet mask to binary and count the number of contiguous 1 bits from the left. That count is the CIDR prefix length.
Can any value between 0 and 255 appear in a subnet-mask octet?
No. Valid mask octets follow contiguous-bit patterns such as 0, 128, 192, 224, 240, 248, 252, 254 and 255, subject to their correct position within the full mask.
Why is 255.255.253.0 not a valid subnet mask?
The octet 253 is binary 11111101, which contains a zero followed by another one. A valid subnet mask cannot contain non-contiguous network bits.
How many bits are in an IPv4 subnet mask?
Every IPv4 subnet mask contains exactly 32 bits.
Does this tool calculate the number of usable hosts?
No. This calculator is intentionally limited to subnet-mask, CIDR and binary conversion.
Does this calculator find the network and broadcast address?
No. Network-address and broadcast-address calculations are outside the scope of this tool.
Scroll to Top