learn

CIDR notation and subnet masks

What /24 means, how to turn a prefix into a subnet mask, how many hosts fit, private ranges (RFC 1918) and a worked example of network and broadcast.

What /24 means

CIDR notation (Classless Inter-Domain Routing, RFC 4632) writes a network as an address followed by a slash and a number: 192.168.1.0/24. The number is the prefix length, how many of the 32 bits of an IPv4 address identify the network; the remaining bits identify hosts inside it. A /24 fixes the first 24 bits and leaves 8 bits, or 256 addresses, for that network. CIDR replaced the old A, B and C classes in 1993 so networks could have any size.

Prefix, mask and hosts

The subnet mask is the prefix written as an address: 24 ones followed by 8 zeros is 255.255.255.0.

PrefixMaskAddressesUsable hosts
/8255.0.0.016,777,21616,777,214
/16255.255.0.065,53665,534
/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 (point-to-point links, RFC 3021)
/32255.255.255.25511 (a single host)

The rule: a /n has 2^(32 − n) addresses, and two of them are reserved, the network address and the broadcast address, so usable hosts = 2^(32 − n) − 2. Cloud providers may reserve more: AWS keeps 5 addresses of every VPC subnet.

A worked example

Take 10.20.30.77/26. The mask has 26 ones, so the last octet keeps 2 network bits: blocks of 64 addresses (0, 64, 128, 192). 77 falls in the block that starts at 64.

Value
Mask255.255.255.192
Network10.20.30.64
First host10.20.30.65
Last host10.20.30.126
Broadcast10.20.30.127
Usable hosts62

In binary, 77 is 01001101; keeping the first two bits (01) and zeroing the rest gives 01000000 = 64. The subnet calculator does this for any address, the range expander turns a start and end address into the smallest CIDR, and decimal to binary shows the bits of each octet.

Private ranges and IPv6

  • RFC 1918 private ranges: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. They are not routed on the internet.
  • Carrier-grade NAT uses 100.64.0.0/10 (RFC 6598).
  • In IPv6 the same notation applies to 128 bits: a LAN is normally a /64, a site often gets a /48, and /128 is one address. You can create a private IPv6 prefix with the ULA generator.

FAQ

How many hosts are in a /24?

256 addresses, 254 usable hosts, because the network (.0) and broadcast (.255) addresses are reserved.

What is the difference between /24 and 255.255.255.0?

None: they are two ways of writing the same mask. CIDR is shorter and works for any prefix length.

Can two subnets overlap?

They must not inside one routed network. 10.0.0.0/16 contains 10.0.5.0/24; using both as separate subnets causes routing conflicts.

Why does a /31 have two usable addresses?

RFC 3021 allows /31 on point-to-point links, where no broadcast address is needed, so both addresses can be used.