Every network engineer eventually faces the moment when there's no calculator handy and you need to know whether 192.168.1.100 sits inside 192.168.1.96/27. The good news: subnet math is mostly memorization and one shortcut called the magic number.

The only formula you really need

For any prefix length n, the subnet has 2^(32 - n) total addresses. Subtract 2 for the network and broadcast and you have the usable host count. That's the whole game.

The magic number trick

To find where a subnet starts and ends without doing binary math, you use the magic number: 256 − relevant_mask_octet.

For a /27, the mask is 255.255.255.224. The relevant octet is the last one, 224. Magic number = 256 − 224 = 32. Subnets fall on multiples of 32 in that octet: .0, .32, .64, .96, .128, .160, .192, .224.

So if someone gives you 192.168.1.100/27, the network is 192.168.1.96 (the closest lower multiple of 32), the broadcast is 192.168.1.127 (one before the next multiple), and the usable range is 192.168.1.97 through 192.168.1.126.

Four worked examples

Example 1: 192.168.1.0/24

Mask is 255.255.255.0. Last octet of mask is 0, so the magic number is 256 — meaning the whole octet flips between subnets. Network = 192.168.1.0, broadcast = 192.168.1.255, usable = 192.168.1.1192.168.1.254 (254 hosts).

Example 2: 10.5.3.50/27

Magic number = 32. Multiples of 32: 0, 32, 64, 96. The value 50 sits between 32 and 64. Network = 10.5.3.32, broadcast = 10.5.3.63, usable = 10.5.3.3310.5.3.62 (30 hosts).

Example 3: 172.16.5.200/28

Magic number = 16. Multiples of 16: 0, 16, 32… 192, 208. The value 200 sits between 192 and 208. Network = 172.16.5.192, broadcast = 172.16.5.207, usable = 172.16.5.193172.16.5.206 (14 hosts).

Example 4: 10.0.0.6/30

Magic number = 4. Multiples of 4: 0, 4, 8… The value 6 sits between 4 and 8. Network = 10.0.0.4, broadcast = 10.0.0.7, usable = 10.0.0.510.0.0.6 (2 hosts).

What about /17 through /23?

The third octet of the mask carries the action. For /22, mask = 255.255.252.0. Magic number on third octet = 256 − 252 = 4. So /22 subnets fall on every 4th value of the third octet: 10.0.0.0, 10.0.4.0, 10.0.8.0, and so on. Each holds 1,024 addresses.

When the cloud changes the answer

Everything above assumes the RFC standard of 2 reserved IPs per subnet. AWS reserves 5, Azure 5, GCP 4, OCI 3. A /28 textbook gives you 14 usable hosts; an AWS /28 gives you 11. Don't size your VPC subnets on textbook math.

For a hands-on tool that does all of this with cloud awareness baked in, try the calculator. For the full reference table from /0 to /32, see the Learn Center.

Try the tools

All the math from this article is one click away in our free, browser-based tools.

Open Calculator → Learn Center More articles
RELATED

More on this topic