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.
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:
| Prefix | Mask | Host bits | Addresses | Hosts |
|---|---|---|---|---|
| /8 | 255.0.0.0 | 24 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 16 | 65,536 | 65,534 |
| /24 | 255.255.255.0 | 8 | 256 | 254 |
| /25 | 255.255.255.128 | 7 | 128 | 126 |
| /26 | 255.255.255.192 | 6 | 64 | 62 |
| /27 | 255.255.255.224 | 5 | 32 | 30 |
| /28 | 255.255.255.240 | 4 | 16 | 14 |
| /29 | 255.255.255.248 | 3 | 8 | 6 |
| /30 | 255.255.255.252 | 2 | 4 | 2 |
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.
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.
That isn't an IPv4 address yet: four numbers from 0 to 255, with dots between, like 10.0.0.1.
network bits host bits
in one sentence Slide the prefix right and the network part grows, the host part shrinks, and fewer hosts fit.
Explore it together
Use the slider above for each of these. Say what you think will happen first, then check.
- Start at /24. The network is
192.168.1.0/24, the broadcast is192.168.1.255, and there are 254 hosts:192.168.1.1to192.168.1.254. - Slide to /25. One more network bit, so the network is cut in half: 128 addresses, 126 hosts. Our
address
.10is in the first half,192.168.1.0to192.168.1.127. The mask is now255.255.255.128. - Change the address to
192.168.1.200, still /25. Now it’s in the second half: network192.168.1.128/25, broadcast192.168.1.255. So with /25,.10and.200are on different networks. - 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.
- 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.
Work out a /27
A host has the address 10.0.0.77/27. Without the slider (then check with it), work out:
- how many host bits, how many addresses and how many usable hosts;
- the network address;
- the broadcast address;
- the first and last usable host;
- 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
- 5 host bits, 32 addresses, 30 usable hosts.
- Network:
10.0.0.64/27. - Broadcast:
10.0.0.95. - First host
10.0.0.65, last host10.0.0.94. - Mask:
255.255.255.224(27 ones: the last octet is11100000= 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.
In
192.168.1.10/24, what does the/24mean?The prefix says how many bits from the left are the network (the street). The other 8 are for hosts.
Which subnet mask means the same as
/24?24 ones and then 8 zeros:
11111111.11111111.11111111.00000000, which is255.255.255.0.How many hosts fit in a
/26?32 − 26 = 6 host bits, and 2⁶ = 64 addresses. Take away the network address and the broadcast: 62.
what happens next?In the animation, the laptop
192.168.1.10/24wants to send to192.168.1.20. What happens next?With /24 the network part is
192.168.1for both: same street, so no router needed.what happens next?Then it wants to send to
203.0.113.80. What happens next?203.0.113isn’t192.168.1: a different street, so it goes out through the gateway.