Recall warm-up
- In a forwarding table with matching routes of /20, /24, and /0, which route wins?
Stuck? Peek at 3.1.5 Forwarding tables & Longest Prefix Match (LPM)
- Match condition: Row
N/n(maskM) matches destinationDiff(D AND M) == N(i.e.Dfalls in[N .. N + 2³²⁻ⁿ − 1]). - Longest Prefix Match (LPM): Among all matching rows, pick the one with the largest prefix length n.
- Default route
0.0.0.0/0: matches every address with n = 0 (used only if nothing else matches).
- Match condition: Row
- What is the alignment requirement for a /26 CIDR block (size 64) in the 4th octet?
Stuck? Peek at 3.1.4 CIDR notation (/n), block size, alignment & route aggregation
- CIDR
a.b.c.d/n: n prefix bits, h = 32 − n host bits, block size N = 2ʰ. - Alignment rule: first address must be divisible by 2ʰ (for
/(24−k), 3rd octet must be divisible by 2ᵏ). - Supernetting: 2ᵏ contiguous, aligned
/nblocks merge into one/(n − k)block.
- CIDR
- How many host bits are needed to support 50 usable hosts in a subnet?
Stuck? Peek at 3.1.3 Subnet masks, subnetting, network/broadcast & usable hosts
- Borrow s bits from host field, leaving h bits → 2ˢ subnets, each with 2ʰ − 2 usable hosts.
- Subnet address =
IP AND Mask; Broadcast = host bits all1s. - Stride Δ = 256 − Mask octet: blocks start at
0, Δ, 2Δ, …and end atΔ−1, 2Δ−1, …. - Valid mask octets: 128, 192, 224, 240, 248, 252, 254, 255.
The Hook
Suppose your company is given one 192.168.1.0/24 block (256 addresses) for three departments: Engineering (100 hosts), Sales (50 hosts), and Admin (25 hosts). With fixed-size subnetting (3.1.3), if you slice into 4 subnets of 64 addresses each, Engineering (100 hosts) won't fit! If you slice into 2 subnets of 128 addresses each, you only get 2 subnets instead of 3!
Variable-Length Subnet Masking (VLSM) solves this by subnetting a subnet — giving each department a block with its own custom prefix length /n.
Predict First
You have 192.168.1.0/24 (offsets 0..255). If you allocate Admin (needs 32 addresses, a /27) FIRST at .0/27 (0..31), where is the first legal aligned position where you can place Engineering (needs 128 addresses, a /25)?
A /25 block (size 128) MUST start at a multiple of 128 (.0 or .128). Since .0..31 is already taken by Admin, Engineering is forced to jump to .128/25, leaving .32..127 splintered! That is why we ALWAYS allocate largest-first.
Core Concept
The VLSM Largest-First Recipe
To allocate variable-sized subnets from a parent CIDR block without alignment gaps:
- For each department needing H usable hosts, find the smallest h such that 2ʰ − 2 ≥ H. Its block size is S = 2ʰ and its prefix is /(32 − h).
- Check feasibility: the sum of all block sizes ∑ Sᵢ must be ≤ the parent block size.
- Sort departments from LARGEST block size S to SMALLEST.
- Assign blocks sequentially starting from the parent's base address. Because powers of 2 are allocated in decreasing order, every block is automatically aligned!
Worked Visual Map: Packing 100, 50, and 25 hosts into /24
Let's trace Engineering (100 hosts → h=7, size 128, /25), Sales (50 hosts → h=6, size 64, /26), and Admin (25 hosts → h=5, size 32, /27) inside 192.168.1.0/24 (256 addresses):
Tree view: Subnetting a Subnet
You can also view VLSM as a binary tree where each split adds 1 to the prefix length (halving the block):
Putting it together
- VLSM allows a single CIDR block to be partitioned into subnets of different sizes (/25, /26, /27, etc.).
- Each subnet needing H usable hosts requires a block of size 2ʰ where 2ʰ − 2 ≥ H.
- Allocating blocks from largest to smallest guarantees CIDR alignment without leaving unusable gaps.
Visual
| Department | Hosts Req | Block Size 2ʰ | Prefix / Mask | Assigned CIDR | Network – Broadcast | Usable Host Range |
|---|---|---|---|---|---|---|
| Engineering | 100 | 128 (h=7) | /25 (255.255.255.128) | 192.168.1.0/25 | .0 – .127 | .1 – .126 (126 hosts) |
| Sales | 50 | 64 (h=6) | /26 (255.255.255.192) | 192.168.1.128/26 | .128 – .191 | .129 – .190 (62 hosts) |
| Admin | 25 | 32 (h=5) | /27 (255.255.255.224) | 192.168.1.192/27 | .192 – .223 | .193 – .222 (30 hosts) |
| (Unallocated) | — | 32 (h=5) | /27 | 192.168.1.224/27 | .224 – .255 | Available for future |
Worked Examples
A point-to-point link between two routers needs only 2 usable IPv4 addresses (one for each router interface). What is the most address-efficient standard CIDR prefix length for this link?
Show the full solution
We need 2ʰ − 2 ≥ 2 → 2ʰ ≥ 4 → h = 2 host bits (block size 4: 1 network, 2 usable hosts, 1 broadcast). Prefix length = 32 − 2 = /30 (mask 255.255.255.252).
Using largest-first VLSM on 192.168.1.0/24 for subnets requiring 100, 50, and 25 usable hosts, what are the CIDR blocks assigned to each, and how many addresses remain unallocated?
Show the full solution
Sizes needed: 100 → 128 (/25), 50 → 64 (/26), 25 → 32 (/27).
• 1st: 192.168.1.0/25 (0..127)
• 2nd: 192.168.1.128/26 (128..191)
• 3rd: 192.168.1.192/27 (192..223)
Remaining addresses = 256 − (128 + 64 + 32) = 32 (block 192.168.1.224/27).
An organisation is granted the block 130.56.0.0/16. It needs to create: 8 subnets of 1000 hosts each, 16 subnets of 500 hosts each, and 32 subnets of 250 hosts each. After allocating these using VLSM, how many addresses remain available in the /16 block?
Show the full solution
Compute block size for each group:
• 1000 usable hosts → 2¹⁰ − 2 = 1022 ≥ 1000 → size = 1024 (/22). 8 × 1024 = 8,192 addresses.
• 500 usable hosts → 2⁹ − 2 = 510 ≥ 500 → size = 512 (/23). 16 × 512 = 8,192 addresses.
• 250 usable hosts → 2⁸ − 2 = 254 ≥ 250 → size = 256 (/24). 32 × 256 = 8,192 addresses.
Total used = 8192 + 8192 + 8192 = 24,576. Total in /16 = 2¹⁶ = 65,536.
Remaining addresses = 65,536 − 24,576 = 40,960.
GATE Traps
- The 2ᵏ usable-host trap: If a question says "a subnet needs 32 usable hosts", 2⁵ = 32 only gives 30 usable hosts! You must allocate 2⁶ = 64 addresses (
/26). - Smallest-first misalignment: If a multiple-choice option assigns
192.168.1.0/26(0..63) and then192.168.1.64/25, reject it immediately —.64/25violates the alignment rule because a/25must start at 0 or 128!
Memory Hook
Pack the big boulders (/25) first, then pebbles (/26, /27) — big blocks only fit on big boundaries!
Connect the Dots
Chapter 3.1 complete! We now know how IPv4 addresses are structured, subnetted, aggregated with CIDR, allocated with VLSM, and looked up via LPM. Next is the Chapter 3.1 Lock-in, and then in Chapter 3.2 we open up the IPv4 datagram header to see all the fields riding alongside the source and destination IP addresses!
Self-Test
- NAT
A department requires 63 usable host addresses. What is the minimum CIDR block size (total number of IPv4 addresses in the subnet) required?
Write your answer before opening the key.
- MCQ
Given block 10.0.0.0/24, we allocate Subnet A (60 hosts) first, then Subnet B (28 hosts), then Subnet C (12 hosts) using largest-first VLSM. What CIDR block is assigned to Subnet C?
- 10.0.0.96/28
- 10.0.0.80/28
- 10.0.0.128/28
- 10.0.0.96/27
- MSQ
Why do we allocate subnets from largest to smallest in VLSM?
- It automatically satisfies the CIDR alignment rule for every subnet when starting from an aligned parent block.
- It prevents splintering of the address space into unusable gaps.
- Routers refuse to forward packets to subnets with prefix length greater than /26.
- Smaller subnets have a larger prefix length /n and can sit on finer address boundaries.
- NAT
A /24 block (256 addresses) is partitioned into one /25 subnet, one /26 subnet, and two /28 subnets. How many addresses remain unallocated?
Write your answer before opening the key.
Rule Card
- Block size for H usable hosts: smallest 2ʰ with 2ʰ − 2 ≥ H; prefix =
/(32 − h). - Largest-first rule: sort subnets by decreasing 2ʰ and allocate sequentially so every block is naturally aligned.
- Non-overlap: sum of block sizes ∑ 2ʰᵢ ≤ 2³²⁻ⁿ_parent, and every block starts on a multiple of its own 2ʰᵢ.
Concept Ledger
- VLSM (Variable-Length Subnet Masking)
- largest-first allocation
- subnetting a subnet
Answer Vault
Try the questions first. Open when you are ready to check.
Warm-up answers
- /24 (Longest Prefix Match).
- The 4th octet of its starting address must be a multiple of 64 (.0, .64, .128, or .192).
- 6 host bits (since 2⁵ − 2 = 30 < 50, and 2⁶ − 2 = 62 ≥ 50).
Self-test answers
- 128 — 6 host bits give 2⁶ − 2 = 62 usable hosts (< 63). So we need 7 host bits: 2⁷ = 128 total addresses (126 usable).
- A — A (60 hosts) → size 64: 10.0.0.0/26 (0..63). B (28 hosts) → size 32: 10.0.0.64/27 (64..95). C (12 hosts) → size 16 (/28): starts at 96 → 10.0.0.96/28.
- B: 64 + 32 = 96, not 80.
- C: Starts right after .95 at .96, not .128.
- D: 12 hosts only need 2⁴ − 2 = 14 ≥ 12, which is a /28 (size 16), not /27.
- ABD — Decreasing powers of 2 naturally land on aligned multiples and leave contiguous free space at the end.
- C: Routers support any valid prefix length up to /30 (and /31, /32).
- 32 — Used = 128 (/25) + 64 (/26) + 2 × 16 (/28) = 224. Remaining = 256 − 224 = 32.
Flashcards
- What block size and prefix length are needed for 32 usable hosts?
Reveal answer
64 addresses (/26), because 2⁵ − 2 = 30 < 32, so h = 6 (2⁶ − 2 = 62 ≥ 32). - Why must VLSM allocate largest subnets first?
Reveal answer
Because a block of size 2ʰ must start at a multiple of 2ʰ; placing a smaller block first misaligns the cursor for a larger block. - What is the standard prefix length for a 2-router point-to-point link?
Reveal answer
/30 (4 addresses: 2 usable).
Exam shortcuts
- Watch out for "62 hosts" vs "64 hosts"! Need 62 usable hosts → 2⁶ − 2 = 62 fits in 64 (
/26). Need 63 or 64 usable hosts → 2⁶ − 2 = 62 is TOO SMALL, must jump to 128 (/25)! — every VLSM question where a department asks for 2ᵏ − 1 or 2ᵏ usable hosts. - Disjoint prefix check: Two CIDR blocks overlap iff the shorter prefix matches the starting address of the longer prefix. — GATE questions asking "Which of the following VLSM allocations is valid (non-overlapping)?"