How to use the Subnet mask binary Calculator tool
- Type a prefix length such as /24 or 24, or a mask such as 255.255.255.0, in the Mask or prefix field.
- Select Convert. The Example button converts /24.
- Read the three result lines: Prefix, Mask and Binary.
- Count the zeros on the Binary line to get the number of host bits, then select Copy if you want to keep the result.
How a subnet mask works in binary
A subnet mask is 32 bits long, like the IPv4 address it belongs to. It is a run of ones followed by a run of zeros. A one means that bit of the address is part of the network number, and a zero means it identifies a host inside that network. The prefix length in CIDR notation is the count of ones, so /24 and 255.255.255.0 are two spellings of one mask.
Because the ones are contiguous, each octet of a valid mask can take only nine values: 0, 128, 192, 224, 240, 248, 252, 254 and 255. Seeing the bits makes it clear why. Each value adds one more leading one to the byte.
Worked example: /19 and 255.255.255.252
Enter /19. Nineteen ones fill the first two octets and the top three bits of the third. Those three bits are worth 128 + 64 + 32 = 224, so the mask is 255.255.224.0. Thirteen zeros remain, which means 2^13 = 8,192 addresses per subnet.
The conversion also runs the other way. Enter 255.255.255.252 and the tool counts 30 ones, reports /30 and shows two host bits, a common size for a point-to-point link.
Input: /19
Prefix: /19
Mask: 255.255.224.0
Binary: 11111111.11111111.11100000.00000000
Input: 255.255.255.252
Prefix: /30
Mask: 255.255.255.252
Binary: 11111111.11111111.11111111.11111100Accepted input and the errors you may see
The field takes one IPv4 value at a time and decides from its shape whether it is a prefix or a mask. The conversion happens in the page, without a network request.
- One or two digits, with or without a leading slash, are read as a prefix length from 0 to 32.
- A number such as 33 fails with Prefix length must be a whole number from 0 to 32.
- Four dotted decimal octets are read as a mask. Each octet must be 0 to 255.
- A mask with a zero before a one, such as 255.0.255.0, fails with Enter a contiguous subnet mask.
- Wildcard masks such as 0.0.0.255 fail the same check, because their ones come last.
- Anything else, including an address with a prefix like 10.0.0.0/8, fails with Enter a dotted IPv4 address.
From mask bits to host counts and wildcard masks
The tool stops at the three lines shown above, but the Binary line gives you what you need for the usual follow-up sums. With z zeros, a subnet holds 2^z addresses. Traditional subnets reserve the first for the network and the last for broadcast, leaving 2^z - 2 hosts. A /26 has six zeros: 64 addresses and 62 usable hosts. RFC 3021 lets a /31 use both of its addresses on point-to-point links.
A wildcard mask, used in access lists and some routing configurations, is the bitwise inverse. Flip every bit of the Binary line, or subtract each octet from 255: 255.255.224.0 becomes 0.0.31.255.
Frequently asked questions
What is /24 as a subnet mask in binary?
It is 11111111.11111111.11111111.00000000, or 255.255.255.0 in dotted decimal. Twenty-four network bits leave eight host bits, enough for 256 addresses.
How do I convert a subnet mask to a CIDR prefix?
Count the one bits. Enter the dotted mask here and the Prefix line gives the count. For example, 255.255.248.0 has 21 ones, so it is /21.
Are /0 and /32 valid?
Yes. /0 gives 0.0.0.0, the mask of the default route that matches every address. /32 gives 255.255.255.255, a mask for one single host. Both are accepted in either notation.
Does it calculate the network and broadcast address?
No. It converts the mask only and takes no IP address. For the network address, broadcast address and address count of a CIDR block, use the Subnet calculator on this site.