Subnetting
Carving a prefix into smaller networks. Masks, hosts, and the all-zero/all-one rules.
Level: intermediate
What is it?
Subnetting divides an address block into smaller prefixes by extending the network prefix and reducing the number of host bits. CIDR notation makes the prefix length explicit, so subnet size is determined by the remaining address bits.
Why does it matter?
Correct subnetting avoids overlap, allocates address space efficiently, and helps define routing and broadcast boundaries. A bad mask can cause failed local delivery or traffic to take an unexpected gateway path.
Mental model
For IPv4 prefix /p, the host portion contains 32-p bits. The number of addresses in the block is 2^(32-p); usable host counts usually subtract network and broadcast addresses, except for special cases such as /31 point-to-point links.
How it works
- A /24 has 8 host bits and 256 total addresses; conventional usable hosts are 254.
- Moving from /24 to /25 splits a block into two equal ranges with 128 addresses each.
- The network address has every host bit zero; the directed broadcast has every host bit one in conventional subnets.
- VLSM lets different subnets use different prefix lengths according to host needs.
- Routing uses longest-prefix match: among matching routes, the most specific prefix is selected.
Steps
- Requirement: a LAN needs about 50 conventional IPv4 host addresses.
- A /26 provides 64 total addresses and normally 62 usable host addresses.
- Choose a correctly aligned /26 block within the parent address range.
- Verify network address, usable host range, broadcast, and that the next subnet does not overlap.
Real-world usage
- Planning LAN and VPC address ranges.
- Solving network/broadcast and usable-host exam questions.
- Debugging incorrect masks or overlapping routes.
Common mistakes
- Counting usable hosts as 2^hostbits for every conventional subnet without exceptions.
- Choosing a prefix size but forgetting its network-block alignment.
- Creating overlapping subnets or reserving no room for future growth.
Interview questions
How many total IPv4 addresses are in a /26?
There are 32−26 = 6 host bits, so 2^6 = 64 total addresses; a conventional subnet generally has 62 usable host addresses.
What is longest-prefix match?
A router chooses the most specific matching route, meaning the route with the greatest prefix length.