GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER NETWORKS

Choose the longest matching routing prefix

6 questions solved the same way, newest first. Back to Computer Networks

How these are solved

Test destination membership for every route, choose the matching row with greatest prefix length, then read its interface/next hop. Host routes/defaults and multiple-destination tallies remain distinct variants.

2 marks · MCQ
Report issue

Applying longest-prefix IP routing

Routing Algorithms

Question 40, GATE 2025: Destination 145.36.109.70 arrives at a router with entries 145.36.0.0/16→E1; 145.36.128.0/17→E2; 145.36.64.0/18→E3; 145.36.255.0/24→E4; default→E5. Which outgoing interface is selected? A E3; B E1; C E2; D E5.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (3 steps)

Approach: First find all matching network prefixes, then choose the most specific (longest) one.
The first two destination octets are 145.36, so the /16 E1 entry matches. The /17 E2 entry additionally requires the high bit of the third octet to be 1, meaning a third octet from 128 through 255. The destination’s third octet is 109, so that entry does not match.
The /18 E3 prefix fixes the first two bits of the third octet to 01, covering 64 through 127. Since 109 lies in that range, it matches. The /24 E4 entry requires third octet 255, so it does not match.
Among E1’s /16, E3’s /18 and the default, /18 is longest. Thus forward to E3, option A. Routing is not a first-listed-match decision, and a longer prefix is relevant only if it actually matches.

Original paper, page 40 · Answer key

2 marks · NAT
Report issue

Choose the longest matching IP prefix

Routing Algorithms

Question 58, GATE 2024: A router has routes 10.1.1.0/24→R1, 10.1.1.128/25→R2, 10.1.1.64/26→R3 and 10.1.1.192/26→R4. It sends 20 packets to each of 10.1.1.16, .72, .132, .191 and .205. How many packets use R2? The abbreviated destinations share prefix 10.1.1.
Tap to enlarge
Answer & solution

Official answer: 40

Step through it (7 steps)

Approach: A router uses the matching route with the greatest prefix length, not the first matching row or every matching route.
1. The /24 covers last-octet values 0–255. The /25 beginning at 128 covers 128–255. The /26 beginning at 64 covers 64–127, and the /26 beginning at 192 covers 192–255.
2. Destination .16 matches only the /24 and uses R1. Destination .72 matches the /24 and the 64/26; the longer /26 wins, so it uses R3.
3. Destinations .132 and .191 match the /24 and the 128/25, with no matching /26. Both therefore use R2.
4. Destination .205 also matches R2's /25, but it matches the more specific 192/26, so it uses R4 instead.
Exactly two hosts use R2, each with 20 packets: 2×20=40.
Answer: 40. Counting .205 for R2 would ignore longest-prefix selection.

Original paper, page 34 · Answer key

2 marks · NAT
Report issue

Routing Algorithms

Question 65, GATE 2023: Routes are 200.150.0.0/16→1, 200.150.64.0/19→2, 200.150.68.0/24→3, 200.150.68.64/27→4, and default→0. Which interface receives destination 200.150.68.118 under longest-prefix matching?
Tap to enlarge
Answer & solution

Official answer: 3

Step through it (3 steps)

The destination matches 200.150.0.0/16 and 200.150.64.0/19, and it also matches 200.150.68.0/24. The /27 entry 200.150.68.64 covers last-octet values 64 through 95, so it does not match 118. The longest matching prefix is consequently the /24 entry, whose interface ID is 3.

Teaching detail. Check network matches rather than selecting the most specific row unconditionally. The /19 mask fixes the top three bits of the third octet and covers third-octet values 64 through 95, including 68. The /24 fixes the entire third octet to 68. The /27 additionally divides the last octet into groups of 32; its network 64 covers 64..95, whereas 118 lies in 96..127. The /27 is more specific but fails to match, leaving /24 as the longest matching row. The default is used only when no more specific route matches.

Original paper, page 69 · Answer key

2 marks · MCQ
Report issue

Routing Algorithms

Question 36, GATE 2015: Routing entries:128.96.170.0/23→interface 0; 128.96.168.0/23→interface 1; 128.96.166.0/23→R2; 128.96.164.0/22→R3; default→R4. Destinations i128.96.171.92, ii 128.96.167.151, iii 128.96.163.151, iv 128.96.165.121. Labels ainterface 0, binterface 1, cR2, dR3, eR4. A i-a, ii-c, iii-e, iv-d; B i-a, ii-d, iii-b, iv-e; C i-b, ii-c, iii-d, iv-e; D i-b, ii-c, iii-e, iv-d.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (6 steps)

Longest-prefix matching sends 171.92 through 170.0/23 to interface 0; 167.151 matches 166.0/23 and 164.0/22, choosing the longer/23 to R2; 163.151 matches only default R4; 165.121 matches 164.0/22 to R3. Thus i-a, ii-c, iii-e, iv-d, A.

A /23 mask covers two adjacent third-octet values, so 170.0/23 covers 170–171 and 166.0/23 covers 166–167. A /22 mask starting 164 covers 164–167. Thus 171 uses interface 0; 167 matches both R2 and R3 but the longer/23 wins; 163 matches neither specific block and uses default R4; 165 matches only 164/22 and uses R3. Never stop at the first matching broad prefix without checking whether a more specific one exists.

Original paper, page 38 · Answer key

2 marks · NAT
Report issue

Routing Algorithms

Question 26, GATE 2014: A CIDR router receives destination 131.23.151.76. Its prefix→interface table is 131.16.0.0/12→3; 131.28.0.0/14→5; 131.19.0.0/16→2; 131.22.0.0/15→1. Which output interface is selected?
Tap to enlarge
Answer & solution

Official answer: 1

Step through it (3 steps)

Step 1: Compare prefixes rather than numerical closeness. With the first octet fixed at 131, /12 covers second octets 16…31, so it matches 23. The /14 entry covers 28…31 and does not match; /16 requires exactly 19 and does not match. Step 2: The /15 entry fixes the top seven bits of the second octet, covering 22 and 23, so it matches. Step 3: CIDR chooses the longest matching prefix, /15 rather than /12. Its output interface is 1.

Original paper, page 58 · Answer key

2 marks · MCQ
Report issue

Longest-prefix routing and host route

Routing Algorithms

Question 55, GATE 2004: Router entries (destination,mask,interface) are (128.75.43.0,255.255.255.0,Eth0), (128.75.43.0,255.255.255.128,Eth1), (192.12.17.5,255.255.255.255,Eth3), and default→Eth2. Which interfaces forward destinations 128.75.43.16 and 192.12.17.10 respectively?
Options:
(A) Eth1,Eth2
(B) Eth0,Eth2
(C) Eth0,Eth3
(D) Eth1,Eth3
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step through it (4 steps)

Step 1: 128.75.43.16 matches both 128.75.43.0/24 and 128.75.43.0/25; the longer /25 prefix selects Eth1.192.12.17.10 does not equal the only 192.12.17.* explicit route, the /32 host route 192.12.17.5 via Eth3, so it uses default Eth2. Matching the first three octets does not make a /32 host route a subnet route.

Step 2: Teaching check: The /25 mask covers last-octet values 0–127, including 16, and outranks /24. The /32 entry matches exactly 192.12.17.5, not all addresses beginning 192.12.17. Any other unmatched destination, including .10, uses default.

Original paper, page 8