How to Calculate Usable Hosts in Any CIDR Block
The formula for usable hosts in a CIDR block is straightforward — but there are edge cases for /31 and /32 that break the pattern. Here's the complete calculation with worked examples.
Every CIDR block has a formula for usable hosts that you can calculate in seconds. Knowing this formula lets you choose the right subnet size for any situation — from a point-to-point WAN link to a large enterprise campus network.
The Standard Formula
For prefix lengths between /1 and /30, the formula is:
Usable hosts = 2^(32 - prefix_length) - 2
The subtraction of 2 removes the network address (all host bits zero) and the broadcast address (all host bits one). Both are reserved and cannot be assigned to a host.
Worked examples:
/24: 28 - 2 = 256 - 2 = 254 usable hosts — see the /24 reference/28: 24 - 2 = 16 - 2 = 14 usable hosts — see the /28 reference/20: 212 - 2 = 4096 - 2 = 4,094 usable hosts/16: 216 - 2 = 65,536 - 2 = 65,534 usable hosts
The /31 Exception (RFC 3021)
A /31 block has only 2 total addresses. The standard formula would give 0 usable hosts — clearly useless. RFC 3021 addressed this by declaring that on point-to-point links (where there are exactly two endpoints and no broadcasts), both addresses can be used as host addresses. So a /31 has 2 usable hosts. This is common on router-to-router links where saving address space matters.
The /32 Exception
A /32 has 1 total address and 1 usable host — itself. The standard formula gives -1, which is meaningless. A /32 is a host route: it identifies a single specific IP address. You will see it in BGP loopback advertisements, firewall rules targeting a single IP, and AWS security group rules. See the /32 reference page for details.
Using the Calculator
Rather than calculating by hand, enter any CIDR block into the CIDR calculator and it immediately shows the network address, broadcast address, first usable IP, last usable IP, and the total and usable host counts. For small prefixes (up to /27 or so), it also lists every IP address in the range individually.
AWS Adjustment
In AWS VPCs, subtract an additional 3 from the usable count: AWS reserves the .1, .2, and .3 addresses in every subnet for the VPC router, DNS resolver, and future use (plus the standard network and broadcast addresses). A /24 in AWS gives 251 usable addresses, not 254.