online posts 15
networking 101: how computers talk

lesson 3.2 · chapter 3 of 5: addresses · 25 min

CIDR: what the /24 means

objective

Read a prefix like /24 and its subnet mask 255.255.255.0, and work out a network’s address, its broadcast address, its first and last host, and how many hosts fit.

1 explain

Where the street ends and the house number starts

How long is the street name?

Picture a long road with two different signs. On one road, the street is called Oak and the houses are numbered 1 to 250. On another, the street is called Oak Avenue North and there are only 6 houses. The longer the street’s name, the fewer houses fit on it.

In lesson 3.1 you saw that an IP address is a network part (the street) and a host part (the house number). But 192.168.1.10 on its own doesn’t say where one ends and the other starts. That’s what the number after a slash is for:

192.168.1.10/24

The /24 is the prefix length. It means the first 24 bits are the network part. An address has 32 bits, so the other 32 − 24 = 8 bits are the host part.

in one sentence The number after the slash says how many bits, from the left, are the network part.

CIDR: just the slash

Writing networks as an address, a slash and a number is called CIDR (say cider). It stands for Classless Inter-Domain Routing. That’s a long name for a simple idea: say exactly how long the network part is, with a slash. (Long ago, networks only came in three fixed sizes called classes, which wasted lots of addresses. Classless means any size you like.)

in one sentence CIDR is the way of writing a network with a slash, like 192.168.1.0/24.

The subnet mask

There’s a second way of writing the same thing, which you’ll see on computers and phones: the subnet mask. Think of a stencil laid over the address: the holes show the network part, and the solid bits cover the host part.

To make it, write a 1 for every network bit and a 0 for every host bit, then turn each group of 8 into a number, like the light switches in lesson 3.1:

/24  =  11111111.11111111.11111111.00000000  =  255.255.255.0

So 192.168.1.10/24 and 192.168.1.10 with mask 255.255.255.0 mean exactly the same thing.

in one sentence The subnet mask, like 255.255.255.0, says the same thing as the slash, written as four numbers.

Two addresses nobody can have

Every network keeps two of its addresses for special jobs:

  • the network address: the very first one, with every host bit 0. It’s the name of the whole network, like the name of the street, for example 192.168.1.0.
  • the broadcast address: the very last one, with every host bit 1. Send a packet to it and everyone on the network gets it (the broadcast from lesson 2.2), for example 192.168.1.255.

So the hosts get everything in between.

in one sentence The first address names the network and the last one means everyone, so hosts get the ones in between.

How many hosts fit?

Every extra host bit doubles the number of addresses: 1 bit gives 2, 2 bits give 4, 3 bits give 8, and so on. Mathematicians write that as 2 to the power of the number of bits: 2⁸ = 256. Take away the two special addresses, and you’ve got the number of hosts:

PrefixMaskHost bitsAddressesHosts
/8255.0.0.02416,777,21616,777,214
/16255.255.0.01665,53665,534
/24255.255.255.08256254
/25255.255.255.1287128126
/26255.255.255.19266462
/27255.255.255.22453230
/28255.255.255.24041614
/29255.255.255.248386
/30255.255.255.252242

Notice: every time the prefix goes up by one, the network is cut in half. Longer street name, fewer houses.

in one sentence Hosts = 2 to the power of the host bits, minus 2; each step bigger in the prefix halves the network.

Why a host cares

Before sending anything, a host asks itself: is this address on my network? It compares the network part of its own address with the network part of the address it’s sending to. Same street? Send it straight there. Different street? Send it to the default gateway (the router, the way out, from lesson 2.1).

in one sentence Same network part: send it straight there; different: send it to the gateway.

2 show

Slide the prefix

Here’s 192.168.1.10. Slide the prefix and watch the line between network bits (blue) and host bits (amber) move, and everything else change with it. You can type a different address too.

address
mask

network bits host bits

in one sentence Slide the prefix right and the network part grows, the host part shrinks, and fewer hosts fit.

3 follow along

Explore it together

Use the slider above for each of these. Say what you think will happen first, then check.

  1. Start at /24. The network is 192.168.1.0/24, the broadcast is 192.168.1.255, and there are 254 hosts: 192.168.1.1 to 192.168.1.254.
  2. Slide to /25. One more network bit, so the network is cut in half: 128 addresses, 126 hosts. Our address .10 is in the first half, 192.168.1.0 to 192.168.1.127. The mask is now 255.255.255.128.
  3. Change the address to 192.168.1.200, still /25. Now it’s in the second half: network 192.168.1.128/25, broadcast 192.168.1.255. So with /25, .10 and .200 are on different networks.
  4. Slide to /30. Only 2 host bits: 4 addresses, 2 hosts. That’s exactly enough for a cable between two routers, which is what /30 networks are often used for.
  5. Slide to /16. 16 host bits: 65,534 hosts. The network part is just 192.168.

Now watch a host make the is it on my network? decision for real:

in one sentence A host compares network parts: the same means send it straight there, different means send it to the gateway.

4 challenge

Work out a /27

A host has the address 10.0.0.77/27. Without the slider (then check with it), work out:

  1. how many host bits, how many addresses and how many usable hosts;
  2. the network address;
  3. the broadcast address;
  4. the first and last usable host;
  5. the subnet mask.
hint

32 − 27 = 5 host bits, so every /27 network is 2⁵ = 32 addresses long.

hint

/27 networks start at multiples of 32 in the last octet: 0, 32, 64, 96, 128… Which one is 77 in?

hint

77 is between 64 and 95. The network starts at 64 and the broadcast is the last one, 95.

show the solution
  1. 5 host bits, 32 addresses, 30 usable hosts.
  2. Network: 10.0.0.64/27.
  3. Broadcast: 10.0.0.95.
  4. First host 10.0.0.65, last host 10.0.0.94.
  5. Mask: 255.255.255.224 (27 ones: the last octet is 11100000 = 128 + 64 + 32 = 224).

Check it: type 10.0.0.77 in the box above and slide to /27.

5 check: test yourself

Pick an answer for each question. You'll see straight away whether it's right, and why. Questions marked what happens next? are about the animations.

  1. In 192.168.1.10/24, what does the /24 mean?

  2. Which subnet mask means the same as /24?

  3. How many hosts fit in a /26?

  4. what happens next?In the animation, the laptop 192.168.1.10/24 wants to send to 192.168.1.20. What happens next?

  5. what happens next?Then it wants to send to 203.0.113.80. What happens next?