Opscraft
IP addressing & subnetting · Lesson 5 of 9 · 5 min read

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.

Enlarge diagramnetwork192.168.10.64usable.65 to .94 (30 hosts)broadcast192.168.10.950-3132-6364-9596-127128-159160-191192-223224-255last octet, /27 blocks of 3277
Figure 1. The block-size trick for 192.168.10.77/27: blocks of 32 start at 0, 32, 64, 96… and 77 falls in the block from 64 to 95.
Swipe sideways to see all of it, or tap to open it full screen.
  • /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.

Enlarge diagram10.0.0.0/24 · 256 addresses.0/26.64/26.128/26.192/26.1 – .62 usable.65 – .126 usable.129 – .190 usable.193 – .254 usable
Figure 2. Splitting 10.0.0.0/24 into four /26 subnets: borrow 2 host bits, get 2² = 4 blocks of 64.
Swipe sideways to see all of it, or tap to open it full screen.

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
Enlarge diagramapp /23 · 400 hostsdb /25mgmtsparespare /2410.10.0.0/22 · 1,024 addresses.0.0.2.0.2.128.3.0
Figure 3. Variable-length subnets carved from 10.10.0.0/22, largest first so every block stays aligned.
Swipe sideways to see all of it, or tap to open it full screen.

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.

Enlarge diagramALIGNED: WORKSMISALIGNED: DOES NOT10.1.0.0/2410.1.1.0/2410.1.0.0/2310.1.1.0/2410.1.2.0/2410.1.1.0 is not ona /23 boundaryPlan aligned blocks per region and account so route tables stay short.
Figure 4. Summarising routes: two neighbouring, aligned /24s combine into one /23. Misaligned blocks cannot.
Swipe sideways to see all of it, or tap to open it full screen.

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')))"