What this subnet calculator does
Enter an IPv4 address and a prefix length (CIDR) or subnet mask. You get the network address, the broadcast address, the first and last usable host, the number of usable hosts, the wildcard mask and the binary view. It also works as a broadcast address calculator. /31 and /32 are handled the way the standards say, not with the "minus 2" rule.
How it's calculated
An IPv4 address is a 32-bit number. A /n prefix means the first n bits name the network and the rest name hosts. The subnet mask has n ones followed by 32 − n zeros. In CIDR notation (RFC 4632), 192.168.1.0/24 means the first 24 bits are the network.
addresses = 2^(32 − n) · usable hosts = 2^(32 − n) − 2 (for /0 to /30)
The all-zeros host address names the network itself. The all-ones host address is the directed broadcast (RFC 919), so both are taken out of the usable count.
/31 and /32
- /31: RFC 3021 lets point-to-point links use a 31-bit prefix. Both addresses are host addresses, and there's no directed broadcast address. So a /31 has 2 usable hosts, not 0.
- /32: one address, a single host (often called a host route). There is no separate network or broadcast address.
Worked example
10.0.0.77 with mask 255.255.255.192. 192 is 11000000 in binary, so the mask is /26 and the last 6 bits are for hosts. 77 is 01001101. Keeping the top 2 bits of the last byte gives 01000000 = 64, so the network is 10.0.0.64. Setting the 6 host bits to 1 gives 01111111 = 127, so the broadcast is 10.0.0.127. The usable hosts run from 10.0.0.65 to 10.0.0.126: 2⁶ − 2 = 62 of them. The wildcard mask is 0.0.0.63.
Subnet reference table
| Prefix | Subnet mask | Addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /22 | 255.255.252.0 | 1,024 | 1,022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 |
| /32 | 255.255.255.255 | 1 | 1 |
Limitations
- IPv4 only. IPv6 uses 128-bit addresses and has no broadcast address.
- Some equipment reserves extra addresses (a gateway, or addresses a cloud provider keeps). Check your platform's rules.
- Private ranges (RFC 1918) are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. The result tells you if your address is in one.