CIDR notation: why a /31 has two usable hosts, what a /32 is for, and the subnet mistakes to avoid

Try it in the tool

CIDR / Subnet Calculator

Subnet math for IPv4 and IPv6 — ranges, masks and host counts.

“How many hosts fit in a /28?” has a one-line answer that is wrong for two of the 33 prefixes. This article starts from the rule everyone learns, shows where it breaks, and goes through the mistakes that come from CIDR notation in real networks: wasted addresses, firewall rules that allow far too much, and subnets that look big enough until a cloud provider takes its share.

The rule, and where it comes from

CIDR notation a.b.c.d/n says that the first n bits of the address are the network and the remaining 32 − n bits number the hosts. A prefix of /24 leaves 8 host bits, so 2^8 = 256 addresses. In the classic design the first address names the network and the last is the broadcast address, so a host can use 256 − 2 = 254.

Put a few common sizes into the CIDR calculator and the table writes itself:

Prefix Netmask Total addresses Usable hosts
/24 255.255.255.0 256 254
/25 255.255.255.128 128 126
/26 255.255.255.192 64 62
/28 255.255.255.240 16 14
/29 255.255.255.248 8 6
/30 255.255.255.252 4 2
/31 255.255.255.254 2 2
/32 255.255.255.255 1 1

Look at the last three rows: the “minus two” stops working exactly where the subnet gets very small.

A /30 wastes half its addresses

Two routers connected by one cable need two addresses. The textbook answer used to be a /30. Ask the calculator about 10.0.0.1 255.255.255.252 and it tells you the network is 10.0.0.0/30, the broadcast 10.0.0.3, the usable range 10.0.0.1 to 10.0.0.2. Four addresses are consumed to number two interfaces. In a network with thousands of links that is thousands of wasted addresses.

/31: both addresses are hosts

RFC 3021 allows a /31 on point-to-point links. With only two ends there is nobody to broadcast to, so neither address is reserved:

10.0.0.0/31
  First host        10.0.0.0
  Last host         10.0.0.1
  Total addresses   2
  Usable hosts      2  (RFC 3021 point-to-point)

A /31 halves the address use of every link. The calculator marks it as point-to-point, because that is the only place it makes sense: do not put a /31 on a network with more than two devices. Modern routers and Linux support it; if a very old device refuses the address x.x.x.0 as a host, fall back to a /30 for that link.

/32: one host

A /32 has no host bits at all, so it names exactly one address:

203.0.113.7/32
  Netmask           255.255.255.255
  Total addresses   1
  Usable hosts      1  (single host)

You meet a /32 in three places: in firewall and security-group rules that allow one office or one server (203.0.113.7/32), in routing tables where a host route points to one machine, and on loopback and service addresses that a router announces. The calculator shows 203.0.113.7 as part of the documentation range reserved by RFC 5737, a good choice for examples because it is never routed on the internet.

The prefix that allows everything: /0

At the other end, 0.0.0.0/0 has no network bits, so it matches all 4,294,967,296 addresses. In a routing table that is the default route, which is what you want. In an access rule it means “from anywhere”: a security group that opens SSH or a database port to 0.0.0.0/0 exposes it to the whole internet. When you see /0 in an allow rule, check that you meant it.

Cloud providers keep addresses for themselves

The calculator counts what the standard says. A virtual network takes more. AWS reserves the first four addresses and the last one of every subnet (network, router, DNS, a future use, and broadcast), so a /28 with 16 addresses gives 11 usable ones, not 14, and /28 is the smallest subnet it allows. Other providers reserve a similar handful. Size subnets with this in mind, and remember that load balancers, NAT gateways and managed databases take addresses of their own inside the subnet.

Private ranges and documentation ranges

RFC 1918 reserves three blocks for private networks: 10.0.0.0/8 (16,777,216 addresses), 172.16.0.0/12 (1,048,576) and 192.168.0.0/16 (65,536). The calculator labels them Private (RFC 1918). When two networks you want to connect use the same private range, they overlap and routing between them breaks, so plan ranges before the second network exists. Three small blocks (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24) are reserved for examples and documentation; use them in tutorials and tickets, never real addresses.

Check where an address sits

A frequent mistake is writing a host address with a prefix as if it were the network: 192.168.10.77/26. The calculator tells you that 192.168.10.77 is a host inside 192.168.10.64/26, with the broadcast at 192.168.10.127 and the usable range 192.168.10.65 to 192.168.10.126. If a tool wants a network address, give it 192.168.10.64/26; some tools silently round, some refuse.

IPv6 in short

IPv6 counts differently. The usual subnet is a /64, which is 2^64 addresses, so nobody counts hosts. A site is usually given a /48, which holds 65,536 /64 subnets, and a single host is a /128. There is no broadcast address, so there is no “minus two”. The calculator takes IPv6 input too, and shows the expanded form of an address, which helps when you compare two shortened addresses by eye.

A checklist before you apply a rule

  1. Is the prefix the one you meant, or did you type a host with /24?
  2. Does the allow rule say /0 anywhere it should say /32?
  3. Do the ranges of the two networks you connect overlap?
  4. Does the subnet still have room after the provider’s reserved addresses and the load balancer’s?
  5. For a link between two routers, is a /31 allowed on both ends?

A wrong subnet or a rule that is too tight rarely announces itself. From the client’s side it usually looks like a hang or a gateway error: see 504 Gateway Timeout and 502 Bad Gateway for how to tell a slow server from a broken path.

Everything you type into the calculator is processed in your browser and never uploaded.

Frequently asked questions

How many usable hosts does a subnet have?

Normally 2^(32 − prefix) − 2: the first address is the network and the last is the broadcast, and neither is given to a host. A /24 has 256 addresses and 254 usable hosts, a /28 has 16 and 14. Two prefixes are different: a /31 has 2 addresses and both are usable, a /32 has 1 and is a single host.

What is a /31 used for?

A point-to-point link between two routers, as RFC 3021 describes. With only two devices on the wire there is nobody to broadcast to, so the network and broadcast addresses are not needed, and a /31 saves half of the addresses a /30 would use. Most routers and operating systems support it; check old equipment.

What does /32 mean in a firewall or security group rule?

Exactly one IPv4 address. 203.0.113.7/32 allows that host and nothing else, which is how you allow one office or one server. A rule that says 0.0.0.0/0 allows every address on the internet, which is almost never what you intended for SSH or a database.

Why does my cloud subnet have fewer usable addresses than the calculator says?

Cloud providers reserve addresses in every subnet for their own use. AWS reserves the first four and the last address, so a /28 gives 11 usable addresses, not 14, and the smallest subnet it allows is a /28. Check the provider's page for the exact number.

What is the IPv6 equivalent?

A /64 is the standard size of one subnet (2^64 addresses, so you never count hosts), a /48 is the usual allocation for a site (65,536 subnets) and a /128 is a single host. IPv6 has no broadcast address, so the 'minus two' rule does not apply.

More guides