What does this calculator do?
This calculator answers the everyday subnetting question in reverse: you know how many hosts a VLAN or segment needs, and you want the smallest block that fits them. It applies the ordinary subnet convention, where the first address is the network and the last is the broadcast, so a block always provides two fewer usable addresses than it contains. The result gives the CIDR prefix, the dotted-decimal mask, the block size, the usable host count and how many host addresses are left spare for growth. The answer is exact, not an estimate. Everything is computed in your browser from the values you type. Nothing is looked up on the network — there is no ping, no DNS query, no WHOIS and no geolocation.
Formula
Because the network and broadcast addresses are reserved, the block must hold your host count plus two, rounded up to the next power of two.
hostBits = ceil(log2(hosts + 2)) prefix = 32 − hostBits totalAddresses = 2^hostBits usableHosts = totalAddresses − 2 spare = usableHosts − hosts
How to use it
Enter the number of hosts that need an address on the segment — count every device, including routers, printers, access points and any addresses a DHCP pool or a virtual IP will consume. Add whatever growth margin your design calls for before entering the number; the spare figure then tells you how much slack remains inside the block.
Worked example
100 hosts: the block must hold 100 + 2 = 102 addresses, and ceil(log2 102) = 7 host bits, so the answer is /25 with mask 255.255.255.128. That block holds 128 addresses, of which 126 are usable, leaving 26 spare host addresses after the 100 you asked for.
Frequently asked questions
Why add 2 to my host count?
An ordinary IPv4 subnet reserves its first address as the network identifier and its last as the broadcast address. Neither can be assigned to a device, so a block must be two addresses larger than the host count you need.
Should I size a subnet exactly to today’s host count?
Usually no. Renumbering a live segment is disruptive, so most designs leave headroom — the spare figure shows exactly how much this block gives you. Note that the next size up doubles the block rather than adding a few addresses.
Does this cover point-to-point links?
Point-to-point links between two routers are normally /31 under RFC 3021, where both addresses are usable and none are reserved. That case falls outside the ordinary +2 convention used here — use the IPv4 Subnet Calculator with a /31 to see it.
Sources
- RFC 4632 — Classless Inter-Domain Routing (CIDR): the address-block, prefix-length and aggregation model used for every IPv4 subnet result on this page.
- RFC 3021 — Using 31-Bit Prefixes on IPv4 Point-to-Point Links: why a /31 has two usable addresses and no broadcast address, and why /32 is a single host.
- RFC 4291 — IP Version 6 Addressing Architecture: prefix and interface-identifier structure (IPv6 has no broadcast address). IPv6 output follows the canonical text form of RFC 5952.
- Reviewed: 2026-08-10
Related calculators
Last updated: 2026-08-10 · v1.0.0 · Report an error