Subnet masks and prefix length
Memorize the prefix-to-mask table and you have memorized half of subnetting. This chapter gives you the table, the trick to derive any mask from scratch, and the formulas for hosts-per-subnet and subnets-per-supernet.
What you'll learn
- Convert any /n prefix to its dotted-decimal mask without a calculator.
- Compute usable hosts for any prefix in two seconds.
- Recognize /30, /31, and /32 by use case.
The mask table — your first piece of muscle memory
A subnet mask is 32 bits: a run of 1s covering the network bits, then 0s covering the host bits. The prefix length is just the count of 1s, so /24 and 255.255.255.0 are the same mask written two ways. The table lists the masks you will meet most, including the ones whose interesting octet is the second or third.
| Prefix | Mask | Usable hosts |
|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 |
| /12 | 255.240.0.0 | 1,048,574 |
| /16 | 255.255.0.0 | 65,534 |
| /20 | 255.255.240.0 | 4,094 |
| /21 | 255.255.248.0 | 2,046 |
| /22 | 255.255.252.0 | 1,022 |
| /23 | 255.255.254.0 | 510 |
| /24 | 255.255.255.0 | 254 — the classic LAN |
| /25 | 255.255.255.128 | 126 |
| /26 | 255.255.255.192 | 62 |
| /27 | 255.255.255.224 | 30 |
| /28 | 255.255.255.240 | 14 |
| /29 | 255.255.255.248 | 6 |
| /30 | 255.255.255.252 | 2 — point-to-point links |
| /31 | 255.255.255.254 | 2 — point-to-point links (RFC 3021) |
| /32 | 255.255.255.255 | 1 — a loopback or a host route |
Why 'hosts = 2^h − 2'
If h is the number of host bits, the subnet has 2^h total addresses. Two are reserved: the all-zeros address is the network identifier and the all-ones address is the broadcast. Everything in between is usable for hosts.
RFC 3021 added a special exception: a /31 has only two addresses, but on a strict point-to-point link they can both be used as host addresses. Most modern routers accept /31 today.
8 more sections in this chapter, plus a 4-question quiz and a hands-on lab.
Modules 2–8 are part of the Course & Lab Pass and All-Access Max — start with a free account
You can see the title, summary, learning objectives and the opening sections. The rest of this chapter, like all of modules 2–8, comes with the Course & Lab Pass and All-Access Max. A free account opens Module 1: How Networks Work end-to-end and saves your labs — start there, no card required.
- Read every chapter in Module 1 — How Networks Work
- Save labs of up to 5 devices
- Save up to 3 topologies
- See the full course syllabus + chapter titles
Free account · no card required · compare plans any time
Build it step by step
- One router, one PC, one pingBuild the smallest network that works: address a router and a PC on the same subnet and get a reply back. · 5 steps · ~10 min · 2 devices
- Two LANs, one routerPut a PC on each of two different subnets and make them talk through a router. · 7 steps · ~12 min · 3 devices
- VLSM for two sitesCarve one /24 into a /26, a /27 and a /30 sized to what each site needs, then route between them with masks that match the plan. · 5 steps · ~18 min · 4 devices