IP Addressing & Subnetting
The math that filters network candidates
Open interactive version (quiz + challenge)Real-world analogy
IP subnetting is like apartment numbering in a huge building. The prefix tells you the building and floor; the host bits tell you the unit. If you can’t split buildings into floors and units without getting lost, you can’t run a real network.
What is it?
Subnetting is how large address spaces are split into manageable, isolated segments with their own gateway and broadcast boundary. It underlies routing, VLAN design, firewalling, and scaling.
Real-world relevance
You must carve 10.0.0.0/16 into 4 branches of roughly 500 hosts each. /23 gives 510 usable hosts per branch — perfect. Branch 1: 10.0.0.0/23. Branch 2: 10.0.2.0/23. Branch 3: 10.0.4.0/23. Branch 4: 10.0.6.0/23. You just planned a network in 30 seconds.
Key points
- IPv4 basics — Addresses are 32 bits written as four octets (e.g., 192.168.10.42). A subnet mask like 255.255.255.0 or a prefix /24 tells you which bits are the ‘network’ and which are the ‘host’.
- CIDR notation — 192.168.10.0/24 means the first 24 bits are network. Prefix length + base address fully defines the subnet. Get comfortable reading /16, /20, /22, /24, /26, /27, /28, /29, /30 quickly.
- Host count math — Hosts per subnet = 2^(32 − prefix) − 2 (minus network and broadcast). /24 → 254 hosts. /28 → 14 hosts. /30 → 2 hosts (common for point-to-point links).
- Network, broadcast, usable range — For 10.0.4.0/22 → network 10.0.4.0, usable 10.0.4.1–10.0.7.254, broadcast 10.0.7.255. Drawing this on paper once makes it muscle memory.
- Private vs public ranges — 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 are private. 169.254.0.0/16 is link-local/APIPA. The rest is mostly public. CGNAT 100.64.0.0/10 is also common in ISPs.
- Default gateway — The router address your machine sends packets to when the destination isn’t on your subnet. Wrong gateway = works locally, fails remotely. Right gateway in a wrong subnet = routing black hole.
- Subnet design tradeoffs — Too big a subnet = more broadcast traffic and blast radius. Too small = constant growth headaches. Allocate with growth in mind (2x current need is a decent rule).
- Subnet-by-hand in 60 seconds — For /26, /27, /28 — know the block sizes: 64, 32, 16. The subnet starts at a multiple of the block size; broadcast is start + (block − 1). Memorize that and you’ll never freeze in an interview.
Code example
// 5 subnet problems to practice
1) Given 192.168.10.0/24, how many usable hosts?
answer: 254
2) Given 10.20.0.0/22, give network, broadcast, usable range.
network 10.20.0.0
broadcast 10.20.3.255
usable 10.20.0.1 - 10.20.3.254
3) You need 60 hosts per site, 10 sites. Minimum prefix?
/26 (62 usable) fits 60; 10 sites means block 10.x.y.0/26 pattern.
4) You need WAN point-to-point. What prefix and why?
/30 -> exactly 2 usable hosts (one per router).
5) Is 10.0.4.130 in 10.0.4.0/25?
/25 covers 10.0.4.0-10.0.4.127. So 10.0.4.130 is NOT in it.Line-by-line walkthrough
- 1. Practice subnet problems block
- 2. Problem 1 — hosts in /24
- 3. Answer
- 4. Blank separator
- 5. Problem 2 — /22 enumeration
- 6. Network address
- 7. Broadcast address
- 8. Usable range
- 9. Blank separator
- 10. Problem 3 — choose prefix for 60 hosts
- 11. Chosen prefix reasoning
- 12. Blank separator
- 13. Problem 4 — WAN link
- 14. /30 chosen with reason
- 15. Blank separator
- 16. Problem 5 — subnet membership check
- 17. Subnet bounds and conclusion
Spot the bug
Plan: Allocate 4 branches of 300 hosts each from 10.0.0.0/16 using /23 subnets:
Branch1 10.0.0.0/23
Branch2 10.0.1.0/23
Branch3 10.0.2.0/23
Branch4 10.0.3.0/23Need a hint?
Do these /23 subnets actually start at correct boundaries?
Show answer
No. /23 block size is 512 addresses, so subnets must start at multiples of 2 in the third octet: 10.0.0.0, 10.0.2.0, 10.0.4.0, 10.0.6.0. ‘10.0.1.0/23’ and ‘10.0.3.0/23’ overlap previous subnets. Correct: Branch1 10.0.0.0/23, Branch2 10.0.2.0/23, Branch3 10.0.4.0/23, Branch4 10.0.6.0/23.
Explain like I'm 5
The internet is a city. Your subnet is your street. The mask decides which houses are on the same street. The gateway is the bridge out of your street. Get the street right and the bridge right — and mail gets delivered.
Fun fact
In many real Bangladesh bank interview panels, subnetting is still the single skill where candidates visibly separate themselves. Not because it’s deep math — because most juniors didn’t practice it enough to answer in 60 seconds.
Hands-on challenge
Without a calculator, on paper, solve all 5 subnet problems in the code block. Then invent 3 more subnets of your own and solve them. Subnetting is a reflex — build it.
More resources
- Subnet Calculator + learning (subnet-calculator.com)
- Subnetting mastery in 30 minutes (Practical Networking)
- RFC 1918 (Private IPv4 ranges) (IETF)