← 🌐 IP Addressing & Network Layer
Subtopic 3 of 5

5.3VLSM, aggregation and longest-prefix match

The idea

VLSM gives each LAN a block just big enough. Aggregation merges neighbouring blocks into one shorter prefix. A router chooses a route by longest-prefix match.

Think of it like this: Street addresses: "Main Street 5" beats "the city of Pune" when you are asked where to deliver; the most specific address wins.

Why it exists

GATE gives a forwarding table and an address, or a list of blocks to aggregate.

How it works

  1. VLSM: round (hosts + 2) up to a power of two, allocate the largest first so every block stays aligned.
  2. Aggregation: two equal blocks merge if adjacent and the first starts on a boundary of the bigger block.
  3. Longest-prefix: list every entry whose prefix matches the destination, take the one with the largest /n.
  4. The default route 0.0.0.0/0 matches everything but loses to any longer prefix.

Worked example: Destination 145.36.109.70, entries 145.36.0.0/16, 145.36.128.0/17, 145.36.64.0/18, default.

The /16 and /18 match (64 to 127 contains 109); /17 covers 128 to 255 and does not. Longest is /18 so the packet leaves on that entry's interface (GATE 2025).

Now play with it

  • →Use the LPM lab with 10.1.1.132 and the GATE 2024 table.
  • →In the aggregation lab enter 12.20.164.0/22, 12.20.168.0/23, 12.20.170.0/23 and see why a single /20 covers extra addresses.
LANhosts neededblockusable rangebroadcast
150192.168.1.0/26192.168.1.1 to 192.168.1.62192.168.1.63
220192.168.1.64/27192.168.1.65 to 192.168.1.94192.168.1.95
310192.168.1.96/28192.168.1.97 to 192.168.1.110192.168.1.111
42192.168.1.112/30192.168.1.113 to 192.168.1.114192.168.1.115

Addresses left over at the end of the parent block: 140. Sort by size, give the biggest LAN the first aligned block, and round each LAN up to the next power of two (hosts + 2).

Exact aggregation200.1.0.0/22
Smallest single covering prefix200.1.0.0/22
Addresses covered by it1024
Addresses actually in your list1024

Two blocks merge only if they are the same size, adjacent, and the first one starts on a boundary of the bigger block. If the covering prefix holds more addresses than the list, aggregating that way would also claim addresses that belong to someone else.

prefixinterfacematches?prefix length
145.36.0.0/16E1yes/16
145.36.128.0/17E2no/17
145.36.64.0/18E3yes/18
145.36.255.0/24E4no/24
0.0.0.0/0E5 (default)yes/0

Forwarded out of E3: the matching entry with the longest prefix (/18) wins.

Check yourself

Which can be a valid CIDR block?

Remember: Longest prefix wins. Blocks start at multiples of their size. Merge adjacent equal blocks.
Exam notes (the dense version)

VLSM gives each LAN a block just big enough: round (hosts + 2) up to a power of two, allocate the biggest first from a block so alignment holds. Route aggregation merges adjacent equal-size blocks into one shorter prefix (4 contiguous /24s become one /22) and shrinks routing tables. A router forwards by longest-prefix match: among all matching entries the one with the longest mask wins; the default route 0.0.0.0/0 matches everything but loses to any longer match.

Previous year questions: IP Addressing & Network Layer (26)

PYQs are grouped by topic, so this is the full set for IP Addressing & Network Layer; try the ones that match this subtopic. Open all 26 on the topic page.