What does the /24 in 192.168.0.0/24 mean? CIDR and subnets

What the /24 after an IP address means, how it relates to the subnet mask, how to work out the network and broadcast addresses and usable hosts, and the private IPv4 ranges.

DevelopmentNetworking

Router settings and cloud consoles are full of notation like 192.168.0.0/24 or 10.0.0.0/16. The number after the slash says how many bits at the front of the address identify the network. The notation is called CIDR (Classless Inter-Domain Routing, RFC 4632).

An IPv4 address is 32 bits

192.168.1.130 is just one 32-bit number, written in four 8-bit chunks as decimal so people can read it.

192      .168      .1        .130
11000000 10101000 00000001 10000010

Those 32 bits are split into two parts:

  • Network part: the leading bits shared by every device on the same network
  • Host part: the trailing bits that tell the devices on that network apart

/24 means the first 24 bits are the network and the remaining 8 are the host.

A subnet mask says the same thing

Write the network part as 1s and the host part as 0s, convert to decimal, and you have the subnet mask. /24 and 255.255.255.0 mean the same thing.

CIDR Subnet mask Addresses Usable hosts
/8 255.0.0.0 16,777,216 16,777,214
/16 255.255.0.0 65,536 65,534
/24 255.255.255.0 256 254
/26 255.255.255.192 64 62
/28 255.255.255.240 16 14
/30 255.255.255.252 4 2
/32 255.255.255.255 1 (a single host)

The number of addresses is 2^(32 − prefix length): 2⁸ = 256 for /24, 2⁶ = 64 for /26. Each extra bit of prefix halves the block.

Why subtract two: network and broadcast addresses

Two addresses in every subnet can’t be given to a device:

  • Network address: all host bits 0. It names the network itself.
  • Broadcast address: all host bits 1. It reaches every device on the network.

So in 192.168.0.0/24 the addresses you can assign are 192.168.0.1 to 192.168.0.254, 254 in all. The exceptions: a link between exactly two devices can use a /31 and both of its addresses (RFC 3021), and a /32 names one single address.

Working one out: 192.168.1.130/26

  1. Find the block size. /26 leaves 6 host bits, so 2⁶ = 64. The last octet is cut into blocks of 64: 0, 64, 128, 192.
  2. Find the block that contains 130: 128–191.
  3. The result:
Item Value
Network address 192.168.1.128
Broadcast address 192.168.1.191
Usable range 192.168.1.129 – 192.168.1.190
Usable hosts 62
Subnet mask 255.255.255.192

Computers do this with bit operations: address AND mask gives the network address; the network address OR the inverted mask (the wildcard mask, 0.0.0.63) gives the broadcast address.

Are two devices on the same network?

A device ANDs the destination address with its own subnet mask. If the result equals its own network address, it sends directly; otherwise it sends to the default gateway (usually the router). 192.168.1.130/26 and 192.168.1.100 look alike in the first three octets, but 100 falls in the 64–127 block, so it is on a different subnet. When the settings look right but two machines can’t reach each other, the mask is worth checking first.

Private IPv4 ranges

Home and office networks use one of the three ranges set aside in RFC 1918. They aren’t routed on the public internet, so many networks can reuse the same addresses.

Block Range
10.0.0.0/8 10.0.0.0 – 10.255.255.255
172.16.0.0/12 172.16.0.0 – 172.31.255.255
192.168.0.0/16 192.168.0.0 – 192.168.255.255

172.16.0.0/12 runs to 172.31 because /12 uses only the first 4 bits of the second octet for the network, leaving the 16 values 16–31. Separately, 169.254.0.0/16 is the link-local range (RFC 3927) a device gives itself when it can’t get an address from DHCP. If you see one, check the connection to the router first.

Check it with the calculator

The IP subnet calculator takes an IPv4 address and a CIDR prefix (or subnet mask) and shows the network and broadcast addresses, usable host range and count, and the wildcard mask. Enter 192.168.1.130/26 to check the example above.

References

  • RFC 4632, Classless Inter-domain Routing (CIDR)
  • RFC 1918, Address Allocation for Private Internets
  • RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links
  • RFC 3927, Dynamic Configuration of IPv4 Link-Local Addresses

Back to the blog