← Interview Prep

IP Addressing & CIDR — Subnetting & Planning

The addressing toolkit: CIDR notation & the mask, subnet math (hosts, block size, network/broadcast), the prefix table to memorize, RFC 1918 & special ranges, VLSM, route summarization/aggregation, wildcard masks, and network-planning principles.

Reading a prefix, subnetting a block on a whiteboard, and summarizing routes are table-stakes networking skills — and constant interview fodder. This is the addressing and planning toolkit: CIDR notation, the subnet math, the special ranges, VLSM, and aggregation, with the shortcuts that make it fast.

An IPv4 address is 32 bits split into a network part and a host part. The prefix length /N says how many leading bits are network. Everything else — host counts, the broadcast address, summarization — falls out of that one split.

CIDR & the mask

CIDR (Classless Inter-Domain Routing) dropped the old A/B/C classes: a prefix is just an address + a length. The mask is the prefix in dotted form — /24 = 255.255.255.0 (24 one-bits). Bits set = network; bits clear = host.

The table to memorize

PrefixMaskBlock sizeUsable hostsTypical use
/24255.255.255.0256254A LAN / VLAN
/25255.255.255.128128126Split a /24 in two
/26255.255.255.1926462Small subnet
/27255.255.255.2243230Small subnet
/28255.255.255.2401614Tiny subnet
/29255.255.255.24886~4 hosts + gw
/30255.255.255.25242Point-to-point link
/31255.255.255.25422*P2P link (RFC 3021, no net/bcast)
/32255.255.255.25511Loopback / host route

*/31 is special: RFC 3021 lets a point-to-point link use both addresses (no network/broadcast waste). /32 is a single host — loopbacks, host routes, anycast VIPs.

Special & reserved ranges

RangeMeaning
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16RFC 1918 private (not routed on the Internet).
100.64.0.0/10CGNAT shared space (RFC 6598).
127.0.0.0/8Loopback.
169.254.0.0/16Link-local / APIPA (auto when DHCP fails).
224.0.0.0/4Multicast.
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24Documentation (TEST-NET) — safe for examples.
0.0.0.0/0Default route (matches everything, shortest prefix).

VLSM — right-size each subnet

Variable-Length Subnet Masking = carve one block into subnets of different sizes to fit each need instead of wasting a /24 on a 2-host link. Allocate largest-first, on power-of-two boundaries.

Given 10.1.0.0/24, need: 100 hosts, 50 hosts, 10 hosts, 2 P2P links

10.1.0.0/25   (.0–.127)   → 126 hosts   [the 100-host LAN]
10.1.0.128/26 (.128–.191) → 62 hosts    [the 50-host LAN]
10.1.0.192/28 (.192–.207) → 14 hosts    [the 10-host LAN]
10.1.0.208/30 (.208–.211) → 2 hosts     [P2P #1]
10.1.0.212/30 (.212–.215) → 2 hosts     [P2P #2]   ...room left to grow

Aggregation / summarization

The inverse: combine contiguous subnets into one shorter prefix to shrink routing tables. Find the common leading bits; that's the summary length.

10.1.0.0/24  +  10.1.1.0/24  +  10.1.2.0/24  +  10.1.3.0/24
first 22 bits are identical  →  summary = 10.1.0.0/22   (covers .0–.3)

Planning principles

Likely interview questions

Related: Protocol Headers · IPv6 · Python — Ranges & Parsing.