IP Subnet Hosts Calculator
Every IPv4 subnet reserves part of its 32-bit address for the network and the rest for individual hosts. The prefix length (the number after the slash in CIDR notation, such as /24) sets where that split falls. Enter a prefix length and this calculator returns the total addresses in the block, the usable host count after reserving the network and broadcast addresses, and the equivalent subnet mask.
IP subnet hosts formula
Host bits = 32 - prefix length
Total addresses = 2 ^ host bits
Usable hosts = total addresses - 2 (network + broadcast)
Subnet mask = prefix bits set to 1, padded with 0 to 32 bits
The "minus 2" reserves the network address (all host bits zero) and the directed broadcast (all host bits one). For /31 and /32 the classic rule yields 0 usable; RFC 3021 permits 2 usable hosts on a /31 point-to-point link.
Worked example: a /26 subnet
A /26 leaves 32 minus 26 = 6 host bits. Total addresses = 2 to the power of 6 = 64. Usable hosts = 64 minus 2 = 62. The matching subnet mask is 255.255.255.192. So a /26 can address 62 devices.
IP subnet hosts: frequently asked questions
How do you calculate the number of hosts in a subnet?
An IPv4 address has 32 bits. If the network prefix length is n, then 32 minus n bits are available for host addresses, giving 2 to the power of (32 minus n) total addresses. For ordinary subnets the network address and broadcast address are reserved, so usable hosts equal 2 to the power of (32 minus n) minus 2.
Why subtract 2 from the host count?
In a standard IPv4 subnet the all-zeros host portion identifies the network itself and the all-ones host portion is the directed broadcast address. Per RFC 791 and common practice neither is assigned to a device, so usable host addresses are 2 to the power of (32 minus prefix) minus 2.
What about a /31 or /32 prefix?
A /32 describes a single host route (1 address, 0 usable under the classic rule). A /31 has only 2 addresses; RFC 3021 allows both to be used as host addresses on point-to-point links, so it carries 2 usable hosts rather than 0. This calculator reports the classic 2-to-the-power minus 2 result and notes these special cases.
Does this work for IPv6?
No. This calculator is for IPv4, which uses 32-bit addresses. IPv6 uses 128-bit addresses and does not reserve a broadcast address, so its host arithmetic differs. Use an IPv6-specific tool for IPv6 prefixes.
Official sources
- IETF RFC 4632: Classless Inter-domain Routing (CIDR).
- IETF RFC 791: Internet Protocol.
- IETF RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links.
Reviewed by the CalculatorHub team, edited by James Graham, 19 June 2026. See our methodology.