Subnetting in Your Head — The Magic-Number Trick (CCNA)
The one method that turns CCNA subnetting from 'do the binary math' into 'glance at the mask, subtract, done'. Worked examples for /27, /28, /22, /21.
If subnetting feels like binary-math homework every time, you’re doing it the slow way. There’s a trick — the magic number — that turns the whole thing into a 10-second mental calculation. Once you have it, you’ll never go back to writing out 32-bit binary on scratch paper.
The idea
Every subnet mask “splits” one octet of the IP address. The size of each subnet’s block, in that octet, is the magic number: 256 − the mask value of that octet.
That’s the whole trick.
Walk through /27
A /27 mask is 255.255.255.224. The interesting octet is the fourth (the only one that isn’t 0 or 255).
Magic number = 256 − 224 = 32.
So subnets in a /27 are 32 addresses wide. Networks land at multiples of 32:
192.168.10.0 /27 → hosts .1 – .30, broadcast .31
192.168.10.32 /27 → hosts .33 – .62, broadcast .63
192.168.10.64 /27 → hosts .65 – .94, broadcast .95
192.168.10.96 /27 → hosts .97 – .126, broadcast .127
Given an IP like 192.168.10.50/27 — what’s its subnet?
Magic number is 32. The largest multiple of 32 that’s ≤ 50 is 32. So the subnet is 192.168.10.32/27. Broadcast is 192.168.10.63. Usable hosts are .33 through .62. Done in 5 seconds, no binary.
Walk through /28
Mask 255.255.255.240. Magic number = 256 − 240 = 16.
Subnets are 16 addresses wide: .0, .16, .32, .48, .64, … .240.
192.168.10.45/28 → biggest multiple of 16 ≤ 45 is 32. Subnet = 192.168.10.32/28. Broadcast = 192.168.10.47. Hosts .33 – .46.
Walk through /22
Now the interesting octet is the third (because /22 borrows into octet 3).
Mask 255.255.252.0. Magic number = 256 − 252 = 4.
Subnets are 4 addresses wide in the third octet: 0.0, 4.0, 8.0, 12.0, …
172.16.10.0/22 → biggest multiple of 4 ≤ 10 is 8. Subnet = 172.16.8.0/22. The full range covers 172.16.8.0 through 172.16.11.255. Broadcast = 172.16.11.255. That’s 1,024 addresses, 1,022 usable hosts.
Walk through /21
Mask 255.255.248.0. Magic number = 256 − 248 = 8.
Subnets are 8 addresses wide in the third octet: 0.0, 8.0, 16.0, 24.0, …
10.50.20.5/21 → biggest multiple of 8 ≤ 20 is 16. Subnet = 10.50.16.0/21, range 10.50.16.0 – 10.50.23.255. Broadcast = 10.50.23.255.
The whole process — 5 steps
- Identify the interesting octet (the one where the mask isn’t 0 or 255).
- Compute the magic number: 256 − mask value of that octet.
- Find the biggest multiple of the magic number that’s ≤ the IP’s value in that octet → that’s your subnet’s network address for that octet.
- Broadcast = network address + magic number − 1.
- Usable hosts = network address + 1 through broadcast − 1.
That’s it. The same five steps work for every mask between /9 and /30.
Memorize the mask table
Don’t compute masks every time — memorize the 8 values:
| Bits | Mask value |
|---|---|
| 1 | 128 |
| 2 | 192 |
| 3 | 224 |
| 4 | 240 |
| 5 | 248 |
| 6 | 252 |
| 7 | 254 |
| 8 | 255 |
A /27 mask in the fourth octet has 3 borrowed bits → look up “3” → 224. /22 mask in the third octet has 6 borrowed bits → “6” → 252.
How many subnets / how many hosts?
- Subnets =
2^(borrowed bits). /27 from a /24 = 3 borrowed bits = 8 subnets. - Hosts per subnet =
2^(host bits) − 2. /27 has 5 host bits =2^5 − 2 = 30hosts.
These are the only formulas you need. Combined with the magic-number trick, you can answer any CCNA subnetting question in under a minute.
A quick drill
Find subnet, broadcast, and usable host range for each:
192.168.20.85/2910.1.1.100/26172.20.5.5/23192.168.0.200/27
Try it before looking. Answers below.
Answers:
/29→ magic 8. 85 → biggest mult of 8 ≤ 85 = 80. Subnet192.168.20.80/29, broadcast.87, hosts.81–.86./26→ magic 64. 100 → biggest mult of 64 ≤ 100 = 64. Subnet10.1.1.64/26, broadcast.127, hosts.65–.126./23→ mask255.255.254.0. Third octet interesting, magic = 256 − 254 = 2. 5 → biggest mult of 2 ≤ 5 = 4. Subnet172.20.4.0/23, broadcast172.20.5.255, hosts172.20.4.1 – 172.20.5.254./27→ magic 32. 200 → biggest mult of 32 ≤ 200 = 192. Subnet192.168.0.192/27, broadcast.223, hosts.193–.222.
If you got 3 of 4 right, you’ve got the technique. If you missed any, you probably forgot to identify the interesting octet first — that’s the #1 mistake.
Where to go from here
If you want more — the full Subnetting library topic covers the binary-math version (slower but more rigorous), VLSM (variable-length masks for efficient address allocation), and the “I have a /24 — give me four equal subnets” pattern. The magic-number trick covers 95% of what you’ll see on the CCNA exam.
Get posts like this by email.
One short, opinionated tutorial per week. Unsubscribe in one click.
We respect your inbox. One email per week, max. Unsubscribe any time.