Subnet masks, prefixes and special addresses

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.

PrefixMaskHost bitsUsable hosts
/8255.0.0.02416,777,214
/16255.255.0.01665,534
/24255.255.255.08254
/25255.255.255.1287126
/26255.255.255.192662
/27255.255.255.224530
/28255.255.255.240414
/29255.255.255.24836
/30255.255.255.25222

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:

ClassFirst octetDefault mask
A1 - 126/8
B128 - 191/16
C192 - 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 rangePrefix
10.0.0.0 - 10.255.255.25510.0.0.0/8
172.16.0.0 - 172.31.255.255172.16.0.0/12
192.168.0.0 - 192.168.255.255192.168.0.0/16

Special addresses

AddressMeaning
127.0.0.0/8 (e.g. 127.0.0.1)Loopback: the device itself
169.254.0.0/16Link-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.255Broadcast 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.

HOME LABS COMMUNITY DASHBOARD