Subnetting

Subnetting in your head: the magic-number method

Most engineers and CCNA candidates relearn subnetting twice a year. The reason isn't that the math is hard — it's that the standard tutorial leads with binary. Here's the method working network engineers actually use on the job and on the exam: one number, a row of powers of two, and the answer falls out.

The cheat sheet you draw on exam day

Before you read another tutorial, learn the table experienced engineers actually scribble on the laminated paper they hand you at a Cisco exam. It's the entire game in 17 rows.

PrefixSubnet maskMagic numberUsable hosts
/16255.255.0.01 (oct 2)65,534
/17255.255.128.012832,766
/18255.255.192.06416,382
/19255.255.224.0328,190
/20255.255.240.0164,094
/21255.255.248.082,046
/22255.255.252.041,022
/23255.255.254.02510
/24255.255.255.01 (oct 3)254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422
/32255.255.255.25511

Look at the patterns. The mask column climbs through 128, 192, 224, 240, 248, 252, 254, 255 — the same eight numbers you'll see across every octet. The magic-number column inverts: 128, 64, 32, 16, 8, 4, 2, 1. Those are your powers of two. They're the only numbers you ever actually need to know.

The magic number, defined

Take any subnet mask. Find the octet that isn't 0 or 255 — call it the interesting octet. Subtract it from 256. That's the magic number.

Worked: 255.255.255.192

Interesting octet = 192. Magic number = 256 − 192 = 64. So this subnet has 64 addresses, and subnet boundaries land at every multiple of 64 in the last octet: 0, 64, 128, 192.

That's the magic number's whole job. It tells you the size of each subnet block, and where the boundaries fall.

Find the network address

Given 192.168.1.137 with mask 255.255.255.192, the magic number is 64. The boundaries in the last octet are 0, 64, 128, 192. 137 falls between 128 and 192, so the network is 192.168.1.128.

You can do this without a calculator: divide the address octet by the magic number, drop the remainder, multiply back. 137 ÷ 64 = 2 r 9, so 2 × 64 = 128. Network = 192.168.1.128.

The powers-of-two shortcut

Working engineers don't divide. They walk a row of powers from left to right, keeping ones that fit.

Powers of two — the only numbers you need
128
64
32
16
8
4
2
1

Same example: 192.168.1.137, mask 255.255.255.192, magic number 64. To find the network, walk the row, keep numbers that are at least the magic number and that fit into the address octet (137) without going over:

128
64
32
16
8
4
2
1

128 fits into 137 (with 9 left over). 64 doesn't fit into 9, so we skip it. 32, 16, 8, 4, 2, 1 are below the magic number, so we stop there. Sum what we kept: 128. Network = 192.168.1.128.

That's the whole technique. The magic number tells you when to stop walking the row. Anything you keep adds up to the network's value in the interesting octet.

Find the broadcast address

The broadcast is the last address in the subnet — one less than the start of the next subnet. Once you have the network and the magic number, the broadcast is one subtraction away.

Worked: 192.168.1.137 with mask 255.255.255.192
Network192.168.1.128
Next network192.168.1.192 (network + magic = 128 + 64)
Broadcast192.168.1.191 (next network − 1)
First usable192.168.1.129 (network + 1)
Last usable192.168.1.190 (broadcast − 1)

Five answers from one method. No binary, no memorizing.

Cross-octet masks (255.255.252.0 and friends)

The trickier exam questions hide the interesting octet in the third position instead of the fourth. Same method — just shift left.

Worked: 10.5.137.42 with mask 255.255.252.0

Interesting octet = the third one (252). Magic number = 256 − 252 = 4. So subnet boundaries fall every 4 in the third octet: 0, 4, 8, 12, … 136, 140, …

137 falls between 136 and 140. The network's third octet is 136. Once the third octet snaps to a boundary, the fourth wraps from 0 to 255 — that's the rest of the subnet.

Network10.5.136.0
Broadcast10.5.139.255
Hosts1,022
The walking-the-row version: magic number 4, walk from 128. Keep what fits into 137 and is ≥ 4: 128 + 8 = 136. That's the third octet of the network.

Two special cases worth memorizing

The mask 255.255.255.254

Looks broken. It isn't. RFC 3021 formalized using both addresses on point-to-point links — saving you four IPs every time you connect two routers. Modern Cisco IOS, Juniper, and Linux all honor it; older equipment may not.

The mask 255.255.255.255

A single host. Used for loopbacks, host routes, and "this exact IP" rules in firewalls. There's no range and no broadcast — the address is the network.

What about IPv6?

IPv6 doesn't use dotted-decimal masks. The prefix length stands on its own (2001:db8::/48), and there's no broadcast — multicast replaces it. The three cuts to recognize on the exam: /48 is what an ISP delegates to a site; /64 is the universal LAN size (per RFC 4291); /128 is a single host. The host space inside a /64 is so large no one calculates a "broadcast address" — questions about IPv6 usually ask whether one address falls inside a given prefix.


Practice it until it's automatic

Slash is a study companion for engineers and CCNA candidates. The Practice tab generates random questions across /22, /23, and /25/30, drills you on network/broadcast/first/last host with the magic-number method, and shows the powers-of-two row with your magic number highlighted on every reveal. The cheat sheet above lives in the app, the calculator's still there for spot-checks. Free on iPhone, iPad, and Mac.

Download Slash