ShareYourGroupShareYourGroupSubnet and Ports

How many hosts in a subnet: the formula and a table

Usable hosts = 2 to the power of the host bits, minus 2. The exceptions are /31 and /32.

The formula

An IPv4 address has 32 bits. With a prefix of p, the number of host bits is 32 - p, and the block has 2^(32 - p) addresses. Two of them are reserved in an ordinary subnet: the network address (all host bits zero) and the broadcast address (all host bits one). So:

usable hosts = 2^(32 - p) - 2

For /24: 2^8 = 256 addresses, 254 hosts. For /26: 2^6 = 64 addresses, 62 hosts. For /20: 2^12 = 4,096 addresses, 4,094 hosts.

The exceptions

Table

PrefixSubnet maskAddressesUsable hosts
/16255.255.0.065,53665,534
/17255.255.128.032,76832,766
/18255.255.192.016,38416,382
/19255.255.224.08,1928,190
/20255.255.240.04,0964,094
/21255.255.248.02,0482,046
/22255.255.252.01,0241,022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422
/32255.255.255.25511

Planning with the table

  1. Count the devices now. Add printers, cameras, phones and anything with an address.
  2. Add growth. A rule of thumb is to leave a quarter to a half free.
  3. Add one for the router (the gateway).
  4. Pick the smallest prefix whose usable hosts cover the total.

Cloud networks reserve more

Cloud providers often reserve more addresses in each subnet for their own use (for example for the gateway and DNS). Check your provider's documentation: the usable number can be smaller than the formula.

Common mistakes

  1. Using the total number of addresses as the number of hosts.
  2. Forgetting the gateway.
  3. Choosing a subnet that is exactly big enough. Networks grow.
How many hosts does a /29 have?

2^3 - 2 = 6.

How many addresses does a /22 have?

2^10 = 1,024 addresses and 1,022 usable hosts.

This is an independent guide. It is not connected with IANA, the IETF or any network equipment maker. Address and port data come from the IANA registries as fetched on 14 November 2026; RFC texts were read from rfc-editor.org. Check the originals for anything you rely on.