Subnet Mask from CIDR Calculator
Network configuration moves between two ways of describing the same thing: the short CIDR prefix like /24 and the dotted-decimal subnet mask like 255.255.255.0. This calculator converts the prefix into the mask and tells you how many usable host addresses the block holds. You enter the prefix length, a number from 0 to 32, and it builds a 32-bit mask by setting that many leading bits to 1 and the rest to 0, then writes those bits as four decimal octets. It also computes the host capacity: a prefix of n leaves 32 minus n host bits, so the subnet contains 2 to the power of (32 minus n) addresses, of which two are reserved, the network address at the bottom and the broadcast address at the top, leaving the rest assignable to devices. That is why a /24 yields 256 total addresses but 254 usable hosts. A larger prefix means more network bits and a smaller subnet, so a /30 is a four-address link while a /16 spans tens of thousands of addresses. The tool is built for IPv4. Every result here is computed deterministically from the prefix you enter, and the worked example below reconciles exactly to the calculator.
A CIDR prefix sets the first n bits of a 32-bit mask: a /24 gives the subnet mask 255.255.255.0. With 8 host bits it holds 256 addresses and 254 usable hosts after reserving the network and broadcast addresses.
Subnet mask method
mask = first n bits set to 1, rest 0
total addresses = 2^(32 - n)
usable hosts = 2^(32 - n) - 2
n = CIDR prefix length
Setting the leading n bits of a 32-bit value produces the mask, written as four octets. The remaining bits count the host addresses, two of which are reserved for the network and broadcast addresses.
Worked example
Convert a /24 prefix to a subnet mask and host count.
- Set the first 24 bits: 11111111.11111111.11111111.00000000
- As octets: 255.255.255.0
- Host bits: 32 - 24 = 8, so 2^8 = 256 addresses
- Usable hosts: 256 - 2 = 254
A /24 is mask 255.255.255.0 with 254 usable hosts. These are the calculator's default inputs, so the result above matches the widget exactly.
Common CIDR prefixes
| Prefix | Subnet mask | Usable hosts |
|---|---|---|
| /30 | 255.255.255.252 | 2 |
| /28 | 255.255.255.240 | 14 |
| /24 | 255.255.255.0 | 254 |
| /16 | 255.255.0.0 | 65,534 |
Networking and data standards: US National Institute of Standards and Technology (NIST).
Subnet mask calculator: frequently asked questions
How do I convert a CIDR prefix to a subnet mask?
Set the first n bits of a 32-bit value to 1 and the rest to 0, where n is the prefix length, then write the 32 bits as four dotted-decimal octets. A /24 prefix sets the first 24 bits, giving 255.255.255.0 as the subnet mask.
How many usable hosts does a prefix allow?
A prefix of n leaves 32 minus n host bits, so the block holds 2 to the power of (32 minus n) addresses. Two are reserved, the network address and the broadcast address, so usable hosts equal that total minus 2. A /24 gives 256 minus 2, which is 254 usable hosts.
Why are two addresses subtracted?
Every IPv4 subnet reserves its first address as the network identifier and its last as the broadcast address, neither of which can be assigned to a device. That is why a block of 256 addresses provides 254 usable host addresses rather than 256.
What does the slash notation mean?
The slash and number, such as /24, is CIDR notation for the prefix length, the count of leading bits that identify the network. A larger number means more network bits and fewer host bits, so a /30 is a tiny subnet while a /16 is a large one.
Does this apply to IPv6 as well?
The prefix concept carries over to IPv6, but IPv6 uses 128-bit addresses and does not reserve a broadcast address, so the host math differs. This calculator is built for IPv4, where the 32-bit mask and the minus-2 host rule apply.
Official sources
- Networking, addressing and data standards: US National Institute of Standards and Technology (NIST). As at 25 June 2026.
Reviewed by the CalculatorHub team, edited by James Graham, 25 June 2026. See our methodology. This is general information, not financial, tax, legal or investment advice.