taap.digitalnetwork engineering toolkit

Hosts to subnet mask calculator

Type the number of hosts a VLAN or segment must hold. The tool returns the tightest prefix that fits, how many addresses are left over and what the next size up would give you.

hosts2mask

The rule

A subnet with h host bits has 2h addresses, two of which are reserved for the network and broadcast. To fit N hosts you need the smallest h that satisfies:

2h − 2 ≥ N  →  h = ⌈log2(N + 2)⌉  →  prefix = 32 − h

Special cases: one host is a /32 and two hosts fit a /31 (RFC 3021, point-to-point only).

Worked example: 50 hosts

N + 2 = 52. The next power of two is 64 = 26, so h = 6 and the prefix is /26 (mask 255.255.255.192). A /26 gives 62 usable addresses, leaving 12 spare (19.4%). The next size up, /25, gives 126 hosts.

Reference table

PrefixMaskAddressesUsable hosts
/30255.255.255.25242
/29255.255.255.24886
/28255.255.255.2401614
/27255.255.255.2243230
/26255.255.255.1926462
/25255.255.255.128128126
/24255.255.255.0256254
/23255.255.254.0512510
/22255.255.252.01,0241,022
/21255.255.248.02,0482,046
/20255.255.240.04,0964,094

Count more than end users

The host count a subnet must hold is rarely just the number of people. Before sizing, add:

  • The gateway address, plus two more if you run HSRP/VRRP (one per router plus the virtual IP).
  • Printers, APs, IP phones, cameras and IoT devices that share the VLAN.
  • DHCP churn: devices that reconnect with a new MAC (randomized MACs on phones and laptops) can hold leases until they expire.
  • Growth over the expected life of the design, typically three to five years.

A good rule of thumb is to size for 1.5× the current count, then round up to the next prefix. In RFC 1918 space, address scarcity is rarely the constraint; broadcast domain size is. Keeping user VLANs at /24 or smaller limits ARP and broadcast traffic and makes failure domains easier to reason about.

Exam shortcut

For CCNA-style questions, memorize the powers of two up to 212 (4,096). Add 2 to the host count, find the first power of two that is equal or larger, and subtract its exponent from 32. For 500 hosts: 502 → 512 = 29 → /23. For 1,000 hosts: 1,002 → 1,024 = 210 → /22. If the question also gives a number of subnets, check that the borrowed bits still leave enough room for both.

Applying it

! Cisco IOS DHCP pool for a /26
ip dhcp pool USERS
 network 10.10.20.0 255.255.255.192
 default-router 10.10.20.1

Frequently asked questions

How many hosts fit in a /24?

254 usable: 256 addresses minus the network and broadcast addresses.

I need exactly 62 hosts. Is a /26 enough?

Yes, a /26 gives exactly 62 usable addresses, but with zero headroom. If anything else joins the VLAN (a gateway, a second router), you need a /25.

Why not just use a /16 for everything?

One huge broadcast domain amplifies ARP, broadcast and multicast traffic, and a loop or broadcast storm takes down every host. Smaller subnets contain failures.

Study and design tool. Validate any configuration in a lab and against vendor documentation before applying it in production.