Subnetting step by step
The block-size method
The interesting octet is the one where the mask isn't 255 or 0. Block size = 256 − mask value in that octet. Subnets start at multiples of the block size in that octet.
Example 1 — network and broadcast of 192.168.10.77/27.
- /27 → mask 255.255.255.224 → block = 256 − 224 = 32.
- Subnets in the 4th octet: 0, 32, 64, 96, 128... → 77 falls in 64–95.
- Network 192.168.10.64, broadcast 192.168.10.95, usable .65–.94 (30 hosts), gateway often .65.
Example 2 — is 10.0.5.20 inside 10.0.4.0/23?
- /23 → mask 255.255.254.0 → block 2 in the 3rd octet → subnets 10.0.0.0, 10.0.2.0, 10.0.4.0, 10.0.6.0...
- 10.0.4.0/23 spans 10.0.4.0 – 10.0.5.255 → yes, 10.0.5.20 is inside.
Example 3 — range of 172.16.8.0/21.
- /21 → 255.255.248.0 → block 8 in the 3rd octet → 172.16.0.0, 172.16.8.0, 172.16.16.0...
- Range 172.16.8.0 – 172.16.15.255 (2,046 usable).
Example 4 — are 192.168.1.10/25 and 192.168.1.200/25 in the same subnet?
- /25 → block 128 → subnets .0–.127 and .128–.255 → no; they need a router.
Example 5 — what's wrong with host 10.0.1.5/24 and gateway 10.0.2.1? The gateway is in 10.0.2.0/24, outside the host's subnet 10.0.1.0/24 — the host can't ARP for it, so all off-subnet traffic fails.
Sizing a subnet for N hosts
Find the smallest power of two ≥ N + 2 (traditional) — or N + 5 in AWS:
- 50 hosts → 64 addresses → /26 (62 usable; 59 in AWS).
- 500 hosts → 512 → /23.
- 1,000 pods → 1,024 → /22 (1,019 usable in AWS) — and leave headroom.
Splitting a network (subnetting)
Borrowing k host bits creates 2^k subnets.
Split 10.0.0.0/24 into 4 equal subnets → borrow 2 bits → /26 (block 64):
| Subnet | Range | Usable |
|---|---|---|
| 10.0.0.0/26 | .0 – .63 | .1–.62 |
| 10.0.0.64/26 | .64 – .127 | .65–.126 |
| 10.0.0.128/26 | .128 – .191 | .129–.190 |
| 10.0.0.192/26 | .192 – .255 | .193–.254 |
How many /24s in a /16? 2^(24−16) = 256. How many /20s in a /16? 16.
VLSM — variable-length subnets
Real networks carve different sizes from one block, largest first to keep alignment. From 10.10.0.0/22 (1,024 addresses):
- App subnet, 400 hosts → 10.10.0.0/23 (.0.0–.1.255)
- DB subnet, 100 hosts → 10.10.2.0/25 (.2.0–.2.127)
- Mgmt, 50 hosts → 10.10.2.128/26
- Spare: 10.10.2.192/26 and 10.10.3.0/24
Summarisation (supernetting)
Contiguous, aligned blocks can be advertised as one route:
10.1.0.0/24+10.1.1.0/24→ 10.1.0.0/23.192.168.0.0/24…192.168.3.0/24→ 192.168.0.0/22.
Alignment matters: 10.1.1.0/24 + 10.1.2.0/24 can't be summarised as a /23 (10.1.1.0 isn't on a /23 boundary). Good IP plans allocate aligned blocks per region/account so route tables (Transit Gateway, on-prem) stay small.
Checking your work with tools
ipcalc 192.168.10.77/27
python3 -c "import ipaddress as i; n=i.ip_network('10.0.4.0/23'); print(n.network_address, n.broadcast_address, n.num_addresses, i.ip_address('10.0.5.20') in n)"
python3 -c "import ipaddress as i; print(list(i.ip_network('10.0.0.0/24').subnets(new_prefix=26)))"
python3 -c "import ipaddress as i; print(i.ip_network('10.0.0.0/16').overlaps(i.ip_network('10.0.128.0/17')))"