Exercises — IPv4 — address format, classes, subnetting, CIDR notation
Before we start, one picture to fix the vocabulary every solution uses — the line that cuts an address into network bits and host bits.

L1 — Recognition
Problem 1.1
What is the subnet mask, in dotted-decimal, for the prefix /20?
Recall Solution 1.1
WHAT we want: turn a prefix length into 32 mask bits, then read them as four decimal octets. WHY: the mask is defined as ones followed by zeros.
- ones, then zeros:
- Third octet
11110000. - Answer:
255.255.240.0.
Problem 1.2
Which class does the address 172.31.5.9 belong to under classful rules, and what is its default prefix?
Recall Solution 1.2
WHAT: classify by the first octet, because the class is literally decided by the leading bits of that octet — and the leading bits pin down a decimal range. WHY the ranges are what they are: the first octet is 8 bits , with place values .
- Class A starts with
0: so . The largest such octet is01111111, smallest00000000→ range 0–127 (usable 1–126, since 0 and 127 are reserved). - Class B starts with
10: so . Smallest10000000, largest10111111→ range 128–191. - Class C starts with
110: so . Smallest11000000, largest11011111→ range 192–223. Now apply it: first octet . Since , its top two bits are10⇒ Class B. - Class B default:
10leading bits, 16 network bits ⇒ default prefix /16. - Answer: Class B,
/16.
Problem 1.3
How many usable hosts does a /29 network provide?
Recall Solution 1.3
WHAT: count host patterns, then remove the two reserved ones. WHY subtract 2: the all-zeros host pattern is the network address and the all-ones host pattern is the broadcast address — neither is assignable to a machine.
- host bits ⇒ total patterns.
- Subtract 2 (network + broadcast).
- Answer: usable hosts.
L2 — Application
Problem 2.1
Convert 192.168.5.130 fully into binary (all 32 bits).
Recall Solution 2.1
WHAT: write each octet as a sum of powers of 2, then read the on/off bits. WHY greedy works: at each step the largest power of 2 that fits must be present (if it weren't, all smaller powers together still couldn't reach the value), so subtracting it and repeating reconstructs the exact bit pattern (see Binary and Positional Number Systems).
- Answer:
11000000.10101000.00000101.10000010.
Problem 2.2
For 10.20.30.45/27, find the network address, broadcast address, and the usable host range.
Recall Solution 2.2
WHAT: only the last octet is interesting because , so the mask breaks inside the 4th octet. WHY only the last octet: the first 24 mask bits fully cover octets 1–3, fixing them; the interesting variation lives entirely in octet 4.
- Host bits . Block size in last octet .
- Boundaries (multiples of 32):
- falls in ⇒ network octet = 32.
- Network:
10.20.30.32. - Broadcast = next boundary ⇒
10.20.30.63. - Usable hosts:
.33through.62(that's addresses).
Problem 2.3
An ISP gives you 203.0.113.0/24. You need 6 subnets, each with the most hosts possible. What new prefix, and how many hosts per subnet?
Recall Solution 2.3
WHAT: borrow the fewest host bits that still gives subnets, so each subnet stays as large as possible. WHY fewest bits: every bit borrowed for subnetting is one fewer host bit, so over-borrowing needlessly shrinks each subnet.
- Need . (too few), ✓ ⇒ borrow .
- New prefix .
- Host bits ⇒ hosts per subnet .
- (You get 8 subnets total, use 6, keep 2 spare — that's fine.)
L3 — Analysis
Problem 3.1
Two hosts 192.168.10.66/26 and 192.168.10.130/26 want to talk directly (same subnet, no router). Can they? Show the reasoning.
Recall Solution 3.1
WHAT: two hosts are in the same subnet iff their network addresses match. Find each network address using the /26 block.
WHY the iff: direct delivery only happens inside one subnet; if network addresses differ, the source must hand the packet to a router.
- block size . Boundaries: .
- is in ⇒ network
192.168.10.64. - is in ⇒ network
192.168.10.128. - ⇒ different subnets.
- Answer: No — they need a router/gateway. Their packets must be routed, they cannot ARP each other directly.
Problem 3.2
Aggregate (supernet) these four routes into the single most specific CIDR block that covers exactly them:
192.168.4.0/24, 192.168.5.0/24, 192.168.6.0/24, 192.168.7.0/24.
Recall Solution 3.2
WHAT: find the longest bit-prefix common to all four third octets; that becomes the aggregate. WHY: a single CIDR block is a fixed prefix plus every combination of the remaining bits — so the aggregate prefix is exactly the shared leading bits. The figure below stacks the four third octets in binary so you can literally see where they agree and where they split.

- Third octets in binary (also shown teal = shared, orange = varying in the figure):
- They agree on the top 6 bits (
000001) and vary only in the low 2 bits ( = all of ). - Common prefix length (first two octets) .
- Answer:
192.168.4.0/22. It covers exactly in the third octet — no more, no less. - Check the range: a
/22spans a block of in the third octet, starting at a multiple of 4 → starts at , covers . ✓
Problem 3.3
Your router's table has these entries. A packet arrives for 10.1.130.7. Which route is chosen and why?
10.1.128.0/18, 10.1.128.0/20, 10.0.0.0/8.
Recall Solution 3.3
WHAT: routers use longest prefix match — among all routes whose network contains the destination, pick the one with the largest prefix (most specific). WHY most-specific wins: a longer prefix names a smaller, more precisely targeted network, which is more likely the correct next hop than a broad catch-all.
- Does
10.0.0.0/8contain it? First octet ✓ — match. - Does
10.1.128.0/18contain it? ⇒ mask covers the first 2 bits of the third octet; block in 3rd octet , starting at ⇒ covers . ✓ — match. - Does
10.1.128.0/20contain it? ⇒ block in 3rd octet , starting at ⇒ covers . ✓ — match. - All three match. Longest prefix wins: .
- Answer: route
10.1.128.0/20is used.
L4 — Synthesis
Problem 4.1
You are handed 172.20.0.0/16. Design a VLSM (Variable-Length Subnet Mask) plan for these needs, using addresses efficiently and in order of size:
- Dept A: 500 hosts
- Dept B: 200 hosts
- Dept C: 50 hosts
- Link P2P: 2 hosts
Recall Solution 4.1
WHAT: with VLSM we size each subnet independently — allocate the largest block first so it lands on a clean boundary, then carve smaller blocks from what's left. WHY largest-first: a big block must begin on a boundary that is a multiple of its own size; placing small blocks first can leave only misaligned gaps too small for the big one. For each need, pick the smallest with required hosts.
Dept A — 500 hosts: need . ✓ ( too small). .
→ 172.20.0.0/23 (covers 172.20.0.0–172.20.1.255, 510 hosts).
Dept B — 200 hosts: ✓. . Next free address is 172.20.2.0.
→ 172.20.2.0/24 (254 hosts).
Dept C — 50 hosts: ✓ ( too small). . Next free is 172.20.3.0, block size .
→ 172.20.3.0/26 (62 hosts, 172.20.3.0–172.20.3.63).
Link P2P — 2 hosts: ✓. . Next free is 172.20.3.64, block size .
→ 172.20.3.64/30 (2 hosts, .65 and .66; net .64, broadcast .67).
Answer table:
| Need | Prefix | Network | Broadcast | Usable hosts |
|---|---|---|---|---|
| A (500) | /23 | 172.20.0.0 | 172.20.1.255 | 510 |
| B (200) | /24 | 172.20.2.0 | 172.20.2.255 | 254 |
| C (50) | /26 | 172.20.3.0 | 172.20.3.63 | 62 |
| P2P (2) | /30 | 172.20.3.64 | 172.20.3.67 | 2 |
Everything fits inside the original /16 with room to spare.
Problem 4.2
Given the address 192.168.100.37 and mask 255.255.255.192, compute the network address by ANDing, and give the CIDR prefix.
Recall Solution 4.2
WHAT: the network address is (address AND mask), bit by bit — this is exactly Subnet Mask and ANDing. WHY AND: a mask bit of 1 keeps the address bit (network part), a mask bit of 0 forces it to 0 (host part cleared), which is precisely what "network address" means. Only the last octet differs from the mask's all-ones octets, so only it needs work.
- Mask last octet ⇒ 2 network bits in that octet ⇒ prefix .
- Address last octet .
- AND with
11000000: - Answer: network
192.168.100.0/26. (Block size ; confirms it.)
L5 — Mastery
Problem 5.1
Point-to-point router links waste addresses. A /30 gives 2 usable hosts but consumes 4 addresses. RFC 3021 allows /31 for such links (both addresses usable, no broadcast). If a backbone has 1000 point-to-point links, how many total addresses are consumed using /30 vs /31, and how many are saved?
Recall Solution 5.1
WHAT: count consumed addresses per link, multiply by 1000, compare. WHY /31 is allowed here: on a link with exactly two endpoints there is no need for a broadcast address, so the usual "" rule is waived — both addresses become usable.
/30: addresses per link. ./31: addresses per link (both usable, special-cased). .- Saved: addresses.
- Answer: /30 uses 4000, /31 uses 2000, saving 2000 addresses across the backbone.
Problem 5.2
You must summarize an org's internal routes into one CIDR block for advertisement. The org owns exactly:
10.6.16.0/24, 10.6.17.0/24, 10.6.18.0/24, 10.6.19.0/24, 10.6.20.0/24, 10.6.21.0/24, 10.6.22.0/24, 10.6.23.0/24.
Find the single aggregate. Then explain why you cannot aggregate 10.6.16.0/24–10.6.22.0/24 (only seven of them) into one clean block.
Recall Solution 5.2
WHAT (Part A) — aggregate all eight: find the longest shared bit-prefix of the third octets. WHY: identical reasoning to 3.2 — a CIDR block is a shared prefix plus all combinations of the free bits.
- Third octets to . In binary: , .
- They agree on the top 5 bits (
00010) and vary in the low 3 bits ( through = all of ). - Prefix .
- Answer:
10.6.16.0/21(block of in the third octet, starting at a multiple of 8 → , covers ). ✓
WHAT (Part B) — why 16–22 (seven) can't be one clean block:
WHY: a single CIDR block must contain a power-of-two count of /24s, and it must start on a matching boundary.
- Seven is not a power of two. Any single prefix that covers through would be
/21(block of 8) — but that block is , which includes 23, an address you might not own/want. - A
/22block (size 4) covers only ; another/22covers . You cannot straddle these two/22groups with one prefix except by going up to/21(all 8). - Conclusion: with exactly you need multiple blocks, e.g.
10.6.16.0/22(16–19) +10.6.20.0/23(20–21) +10.6.22.0/24(22). No single aggregate exists.
Recall Self-check summary (cover and recall)
Usable hosts in /n ::: Same-subnet test for two hosts ::: their network addresses (address AND mask) are equal Router picks which matching route ::: the longest prefix (most specific) Two conditions for a valid CIDR aggregate ::: power-of-two count AND aligned start Smallest to make subnets ::: smallest with
Related: NAT — Network Address Translation · DHCP and APIPA · IPv6 — addressing and notation · 4.3.08 IPv4 — address format, classes, subnetting, CIDR notation (Hinglish)