Subnet Mask Calculator
Enter a CIDR prefix length (0 to 32) to see the dotted subnet mask, wildcard and number of usable hosts.
What the calculator returns
Enter a CIDR prefix from 0 to 32 and the tool returns three things: the dotted-decimal subnet mask, the matching wildcard mask and the number of usable host addresses. The default /24 gives 255.255.255.0, wildcard 0.0.0.255 and 254 usable hosts. The mask and the wildcard are exact complements, so adding them octet by octet always yields 255.
Building the mask from n ones
An IPv4 address is 32 bits. A CIDR prefix of n means the first n bits are the network portion and the remaining 32 − n bits address hosts. The mask simply writes a 1 in every network position and a 0 in every host position, then regroups the 32 bits into four dotted octets.
At /24 that is 24 ones followed by 8 zeros, so the first three octets are 11111111 = 255 and the last is 00000000 = 0. At /26 the last octet is 11000000 = 192, giving 255.255.255.192. The mask is always a run of ones from the left, never a scattered pattern, which is why the valid values in each octet are only 0, 128, 192, 224, 240, 248, 252, 254 and 255.
The host count follows from the zero bits. With 32 − n host bits there are 232−n addresses in the block, minus two that cannot be assigned: the network address and the broadcast address. At /24 that is 28 − 2 = 254.
Prefix lengths from /0 to /32
| CIDR | Subnet mask | Wildcard | Usable hosts |
|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,294 |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,214 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,534 |
| /24 | 255.255.255.0 | 0.0.0.255 | 254 |
| /25 | 255.255.255.128 | 0.0.0.127 | 126 |
| /26 | 255.255.255.192 | 0.0.0.63 | 62 |
| /27 | 255.255.255.224 | 0.0.0.31 | 30 |
| /28 | 255.255.255.240 | 0.0.0.15 | 14 |
| /29 | 255.255.255.248 | 0.0.0.7 | 6 |
| /30 | 255.255.255.252 | 0.0.0.3 | 2 |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 |
Each step from /24 to /25 halves the block, and the usable count halves with it, roughly: 254, 126, 62, 30, 14, 6, 2. That sequence is not a coincidence. Cutting off one more host bit doubles the number of subnets and halves the hosts in each, which is the whole point of subnetting.
Worked example: /24 in detail
The prefix is 24, so the first three octets are all ones and the fourth is all zeros. Dotted decimal: 255.255.255.0. Subtracting each octet from 255 gives the wildcard, 0.0.0.255, which is what an access list or an OSPF statement uses to mean “any value in the last octet”.
Host bits = 32 − 24 = 8. Total addresses = 28 = 256. Subtract the network address (the all-zeros host part) and the broadcast address (the all-ones host part), and 254 remain assignable. In 192.168.1.0/24 that means 192.168.1.1 through 192.168.1.254 are usable, while .0 and .255 are reserved.
Check the mask boundary at /26 instead. The last octet is 11000000, so the block size is 64 and the subnets begin at .0, .64, .128 and .192. Each block holds 64 addresses, of which 62 are usable. Same arithmetic, one fewer host bit, twice as many subnets.
The /31 and /32 exceptions
Two prefixes break the subtract-two rule, and the calculator handles both. A /31 has only two addresses and no room for a separate network and broadcast pair, so RFC 3021 allows both to be used on point-to-point links; the tool returns 2 usable hosts rather than 0. A /32 is a single address with no host bits at all, used for loopbacks and host routes, so it returns 1.
These exceptions matter in router configuration. A /30 is the traditional point-to-point choice with 2 usable addresses out of 4, while a /31 uses the same 2 addresses out of 2 and wastes nothing. On modern gear a /31 saves half the address space on every link, which adds up across dozens of WAN circuits.
Mask versus wildcard
- A subnet mask has 1 for network bits and 0 for host bits: /24 is 255.255.255.0
- A wildcard inverts that, with 0 for bits that must match and 1 for bits that may vary: 0.0.0.255
- Masks configure interfaces; wildcards appear in ACLs, OSPF network statements and some firewall rules
- A wildcard is not required to be a contiguous block of ones, so 0.0.5.255 is legal in an ACL although it is not a valid mask
- Mixing the two is the classic configuration error, since 255.255.255.0 in an ACL means “match nothing in the last octet”
Common mistakes
- Counting host bits instead of addresses: /28 has 4 host bits but 16 addresses, 14 of them usable
- Forgetting the two reserved addresses, which turns a 16-address block into 14 usable ones
- Assuming every prefix follows the subtract-two rule, when /31 and /32 do not
- Writing a non-contiguous mask such as 255.255.255.100, which no device will accept
- Confusing the network address with the first usable address: 10.0.0.0/24 starts at 10.0.0.1 for hosts
- Planning a /24 for 300 devices, when it holds 254 and needs a /23 to fit 510
Choosing a prefix for a host count
Work backward from the device count. For 50 devices you need at least 52 addresses including the two reserved, so 26 = 64 fits and the prefix is 32 − 6 = /26. For 200 devices, 28 = 256 gives 254 usable, so /24. Round up to the next power of two, then subtract that exponent from 32; that single step avoids both wasted space and a subnet that runs out mid-projection.
Why the mask still matters in IPv6
The same notation carries over, but the numbers dwarf IPv4. A typical IPv6 LAN is a /64, which holds 264 addresses, and the reserved-address arithmetic is not used the same way because anycast and neighbour discovery replace broadcast. The mask concept remains identical: a run of ones defines the prefix, and everything after it is host space.
Frequently asked questions
What is a CIDR prefix?
The number of leading bits in an IP address that identify the network, written after a slash. /24 means 24 network bits and 8 host bits, giving 254 usable addresses.
What subnet mask is /24?
255.255.255.0 with a wildcard of 0.0.0.255. It leaves 8 host bits, so the block holds 256 addresses and 254 are usable.
Why are there two fewer usable hosts?
One address is the network address, where all host bits are zero, and one is the broadcast address, where all host bits are one. Neither can be assigned to a device, so a /24 gives 256 − 2 = 254.
What is /26 in dotted decimal?
255.255.255.192, with a wildcard of 0.0.0.63. It holds 64 addresses and 62 usable hosts, and the subnets step in blocks of 64.
How many hosts does a /28 have?
14 usable out of 16 total. Four host bits give 24 = 16, and subtracting the network and broadcast addresses leaves 14.
Why does /31 show 2 usable hosts?
RFC 3021 allows both addresses on a point-to-point link because there is no need for a broadcast address. The usual subtract-two rule would give 0, which would make the prefix useless.
What is the difference between a mask and a wildcard?
A mask has 1s where bits must match the network, and a wildcard has 0s there instead. /24 is mask 255.255.255.0 and wildcard 0.0.0.255; the two always sum to 255 in each octet.
How many addresses are in a /16?
65,536 total and 65,534 usable. Sixteen host bits give 216, and the network and broadcast addresses take the other two.
How do I pick a prefix for 100 devices?
Use a /25. It holds 128 addresses and 126 usable, which covers 100 with room to grow; a /26 at 62 usable would fall short.
Method and sources
- CIDR notation: prefix length maps to a 32-bit subnet mask.