The subnet mask
A subnet mask is also 32 bits: a run of 1s for the network part, then 0s for the host part. 255.255.255.0 is 24 ones then 8 zeros. Instead of writing the mask, we often write the number of ones after a slash: /24. That is the prefix length.
| Prefix | Mask | Host bits | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 24 | 16,777,214 |
| /16 | 255.255.0.0 | 16 | 65,534 |
| /24 | 255.255.255.0 | 8 | 254 |
| /25 | 255.255.255.128 | 7 | 126 |
| /26 | 255.255.255.192 | 6 | 62 |
| /27 | 255.255.255.224 | 5 | 30 |
| /28 | 255.255.255.240 | 4 | 14 |
| /29 | 255.255.255.248 | 3 | 6 |
| /30 | 255.255.255.252 | 2 | 2 |
Remember: Usable hosts = 2host bits − 2. You lose two addresses in every subnet: the first is the network address (the subnet's name) and the last is the broadcast address (sends to everyone in the subnet).
The only numbers that can appear in a mask octet are 0, 128, 192, 224, 240, 248, 252, 254 and 255, because the ones must be in one unbroken run from the left.
Classes (history you still need)
Before prefixes, the first octet fixed the size of a network. You still see the words "class A/B/C" and routers still group routes by class in show ip route:
| Class | First octet | Default mask |
|---|---|---|
| A | 1 - 126 | /8 |
| B | 128 - 191 | /16 |
| C | 192 - 223 | /24 |
| D (multicast) | 224 - 239 | - |
Private and public addresses
Three ranges are kept for private use inside homes and companies. They are never routed on the internet; a router translates them to a public address on the way out (NAT, later in the course).
| Private range | Prefix |
|---|---|
| 10.0.0.0 - 10.255.255.255 | 10.0.0.0/8 |
| 172.16.0.0 - 172.31.255.255 | 172.16.0.0/12 |
| 192.168.0.0 - 192.168.255.255 | 192.168.0.0/16 |
Special addresses
| Address | Meaning |
|---|---|
| 127.0.0.0/8 (e.g. 127.0.0.1) | Loopback: the device itself |
| 169.254.0.0/16 | Link-local (APIPA): a PC gives itself one of these when DHCP fails |
| 0.0.0.0 | "This network" / "any address"; 0.0.0.0/0 is the default route |
| 255.255.255.255 | Broadcast to everyone on the local network |
Common mistake: Seeing 169.254.x.x on a PC almost always means it asked for an address with DHCP and nobody answered. Check the cable, the VLAN, and the DHCP server.