CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 3 · Network Layer

Lesson 3.1.6 · Item 46 of 90

Variable-Length Subnet Masking (VLSM) & block allocation

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. 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 (mask M) matches destination D iff (D AND M) == N (i.e. D falls 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).

    Read lesson 3.1.5

  2. 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 /n blocks merge into one /(n − k) block.

    Read lesson 3.1.4

  3. 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 all 1s.
    • 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.

    Read lesson 3.1.3

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:

VLSM Allocation Algorithm:
  1. 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).
  2. Check feasibility: the sum of all block sizes ∑ Sᵢ must be ≤ the parent block size.
  3. Sort departments from LARGEST block size S to SMALLEST.
  4. Assign blocks sequentially starting from the parent's base address. Because powers of 2 are allocated in decreasing order, every block is automatically aligned!
1. Round each H up
find S = 2ʰ with 2ʰ−2 ≥ H
2. Check ∑ S ≤ Total
fits in parent block?
3. Sort LARGEST first
guarantees alignment!
4. Pack back-to-back
zero wasted gaps
The 4-step VLSM allocation algorithm.

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):

Eng: .0/25 (128)0–127
Sales: .128/26 (64)128–191
Admin: .192/27 (32)192–223
free224–255
0255
Largest-first packing inside 192.168.1.0/24: 128 + 64 + 32 = 224 used, leaving .224/27 (32 addresses) free at the end!

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):

192.168.1.0/24 (256)Eng: .0/25 (128).128/25 (128)Sales: .128/26 (64).192/26 (64)Admin: .192/27 (32)Free: .224/27 (32)
Binary prefix tree of VLSM: no two allocated leaves ever overlap.

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

DepartmentHosts ReqBlock Size 2ʰPrefix / MaskAssigned CIDRNetwork – BroadcastUsable Host Range
Engineering100128 (h=7)/25 (255.255.255.128)192.168.1.0/25.0 – .127.1 – .126 (126 hosts)
Sales5064 (h=6)/26 (255.255.255.192)192.168.1.128/26.128 – .191.129 – .190 (62 hosts)
Admin2532 (h=5)/27 (255.255.255.224)192.168.1.192/27.192 – .223.193 – .222 (30 hosts)
(Unallocated)—32 (h=5)/27192.168.1.224/27.224 – .255Available for future
Complete VLSM allocation table for 192.168.1.0/24.

Worked Examples

Easy

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).

Medium

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).

GATE

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 then 192.168.1.64/25, reject it immediately — .64/25 violates the alignment rule because a /25 must 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

  1. 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.

  2. 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?

    1. 10.0.0.96/28
    2. 10.0.0.80/28
    3. 10.0.0.128/28
    4. 10.0.0.96/27
  3. MSQ

    Why do we allocate subnets from largest to smallest in VLSM?

    1. It automatically satisfies the CIDR alignment rule for every subnet when starting from an aligned parent block.
    2. It prevents splintering of the address space into unusable gaps.
    3. Routers refuse to forward packets to subnets with prefix length greater than /26.
    4. Smaller subnets have a larger prefix length /n and can sit on finer address boundaries.
  4. 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

  1. /24 (Longest Prefix Match).
  2. The 4th octet of its starting address must be a multiple of 64 (.0, .64, .128, or .192).
  3. 6 host bits (since 2⁵ − 2 = 30 < 50, and 2⁶ − 2 = 62 ≥ 50).

Self-test answers

  1. 128 — 6 host bits give 2⁶ − 2 = 62 usable hosts (< 63). So we need 7 host bits: 2⁷ = 128 total addresses (126 usable).
  2. 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.
  3. 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).
  4. 32 — Used = 128 (/25) + 64 (/26) + 2 × 16 (/28) = 224. Remaining = 256 − 224 = 32.

Flashcards

  1. What block size and prefix length are needed for 32 usable hosts?
    Reveal answer64 addresses (/26), because 2⁵ − 2 = 30 < 32, so h = 6 (2⁶ − 2 = 62 ≥ 32).
  2. Why must VLSM allocate largest subnets first?
    Reveal answerBecause a block of size 2ʰ must start at a multiple of 2ʰ; placing a smaller block first misaligns the cursor for a larger block.
  3. 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)?"

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.