IP addresses and subnets
Calculate a subnet boundary
Find the network range represented by a CIDR prefix and see how a longer prefix creates a smaller subnet.
8 minute lesson
A CIDR prefix is a block of addresses sharing the same leading bits. A /24 fixes 24 bits and leaves 8 bits variable, so it contains 256 IPv4 addresses. Every bit you add to the prefix cuts the block in half:
/24: 256 addresses
/25: 128 addresses
/26: 64 addresses
/27: 32 addresses
A /26 fixes two more bits than a /24 and contains 64 addresses. So which 64 addresses does 192.0.2.70/26 sit among? That’s the calculation this lesson is about.
Do the math once by hand
The last byte of 192.0.2.70 is 70. A /26 means blocks of 64 addresses, so the boundaries in that byte are 0, 64, 128, and 192. The value 70 falls between 64 and 128.
That means 192.0.2.70/26 falls in the block from 192.0.2.64 through 192.0.2.127. The network address is 192.0.2.64/26, and 192.0.2.127 is the last address in the block.
The general recipe: work out the block size (2 raised to the number of host bits), find the largest multiple of that size that fits below your address, and that multiple is the start of the subnet.
Then let the computer check you
Python ships an ipaddress module that does exactly this:
python3 -c "import ipaddress; n = ipaddress.ip_network('192.0.2.70/26', strict=False); print(n, n[0], n[-1])"
192.0.2.64/26 192.0.2.64 192.0.2.127
strict=False tells Python you’re giving it a host address, not a network address, and it should find the containing network. The output confirms the hand calculation: network 192.0.2.64/26, first address .64, last address .127.
Try a few of your own. What block contains 10.1.7.200/27? Compute it by hand, then verify. The boundaries in the last byte for a /27 are multiples of 32, so the answer is 10.1.7.192 through 10.1.7.223.
Why this matters in practice
Subnetting is binary boundary calculation, not guesswork based on decimal dots. Modern routing uses prefixes instead of the old class A, B, and C assumptions, so nothing about the address itself tells you where its network starts.
The classic mistake is assuming two addresses are in the same subnet because three dots’ worth of digits match. 192.0.2.60/26 and 192.0.2.70/26 look close, but .60 lives in the 192.0.2.0–.63 block and .70 lives in the next one. They need a router to talk. When neighbors mysteriously can’t reach each other, calculate the boundaries before you trust your eyes.
Lesson completed