INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

Topic lessonTopic: networking foundations

IPv4 routing tables: longest prefix match and next hops

Longest prefix match selects the longest prefix among routes that match the destination IP. It does not select the longest entry in the entire table regardless of the destination. Use a fictional three-route table to read the matching set, the longest entry and its next hop for different destinations.

What you will learn

List every matching entry in one fictional IPv4 table, then explain the longest matching prefix and its next hop.

Prerequisite

Know the ranges denoted by /24 and /25. A next hop is the next direct recipient. Review the existing CIDR and next-hop lessons if needed. This is a reading exercise: it adds no routes, makes no connections and accepts no real routing tables.

Use only these three available routes

A Forwarding Information Base (FIB) contains route information used for forwarding. For this exercise, the three entries below are the only available candidates for one forwarding decision. How routes were learned or installed is outside the lesson.

Fictional forwarding table: row order is not priority
Destination prefixNext-hop labelGiven state
0.0.0.0/0CAvailable
192.0.2.128/25BAvailable
192.0.2.0/24AAvailable

Match the destination before comparing lengths

Check each entry against the leading bits of the destination IP. Remove entries that do not match; only then compare the prefix lengths after the slash. This example has no equal-length competition among the longest matching entries, so one remains.

192.0.2.200: keep three matches, choose /25, then read B
192.0.2.200: keep three matches, choose /25, then read B1: Destination IP — Retain ranges containing the destination — All matching entries. 2: All matching entries — Compare lengths only among matches — Longest match. 3: Longest match — Read another column of the chosen entry — That entry’s next hop123Destination IPAll matchingentriesLongest matchThat entry’s nexthop192.0.2.200: keep three matches, choose /25, then read B1: Destination IP — Retain ranges containing the destination — All matching entries. 2: All matching entries — Compare lengths only among matches — Longest match. 3: Longest match — Read another column of the chosen entry — That entry’s next hop123Destination IPAll matchingentriesLongest matchThat entry’snext hop
  1. Destination IP → All matching entriesRetain ranges containing the destination
  2. All matching entries → Longest matchCompare lengths only among matches
  3. Longest match → That entry’s next hopRead another column of the chosen entry
Destination IP
192.0.2.200
All matching entries
/0, /24 and /25
Longest match
192.0.2.128/25
That entry’s next hop
B

The arrows show a reading sequence, not a packet path, router count or timing. The prefix describes a destination range; B is the next recipient specified by that entry.

Read why /25 is more specific than /24

Two ranges sharing an initial prefix
PrefixFirst addressLast addressTotal addresses
192.0.2.0/24192.0.2.0192.0.2.255256
192.0.2.128/25192.0.2.128192.0.2.255128

192.0.2.200 lies in both ranges. The /25 fixes 25 leading bits and covers only the upper half of this /24, making it more specific. The number 25 is not a device count or speed.

This /25 is contained in the upper half of the /24
This /25 is contained in the upper half of the /241: 192.0.2.0/24 — Range containment: upper half of this /24 — 192.0.2.128/251192.0.2.0/24192.0.2.128/25This /25 is contained in the upper half of the /241: 192.0.2.0/24 — Range containment: upper half of this /24 — 192.0.2.128/251192.0.2.0/24192.0.2.128/25
  1. 192.0.2.0/24 → 192.0.2.128/25Range containment: upper half of this /24
192.0.2.0/24
192.0.2.0–255 / 256 addresses
192.0.2.128/25
192.0.2.128–255 / 128 addresses

Compare the matching set for three destinations

Three readings of the same table
Destination IPAll matching lengthsSelected prefixNext hop
192.0.2.200/0, /24, /25192.0.2.128/25B
192.0.2.25/0, /24192.0.2.0/24A
198.51.100.25/00.0.0.0/0C

192.0.2.25 is outside the /25 starting at 192.0.2.128. That entry is excluded even though it has the greatest length in the table. Compare the matching /24 and /0 instead, and select A from the /24 entry.

A 0.0.0.0/0 prefix fixes zero leading bits, so its range matches every IPv4 address. For 198.51.100.25, neither example /24 nor /25 matches; only /0 remains, selecting C. The /0 also matches 192.0.2.200, but a longer match wins there.

Separate route selection from evidence of connectivity

The fictional table establishes which entry and next hop are selected from the supplied candidates. Link delivery, the return route, traffic controls, application listeners and responses require separate evidence. Selecting C does not establish Internet connectivity.

Explain the matching candidates and the longest among them

Choose an option to see the result and explanation.

Using the original three entries, what is selected for 192.0.2.200?
Read the answer and reason

Answer: /0, /24 and /25 match; choose B from /25 · The matching lengths are 0, 24 and 25. The greatest is 25, selecting next hop B from 192.0.2.128/25.

Using the same table, what is selected for 192.0.2.25?
Read the answer and reason

Answer: A, from /24 among the matching /0 and /24 · 192.0.2.25 is inside /24 and outside /25. Comparing lengths after matching selects A.

Remove only the /0 entry. What does the table say for 198.51.100.25?
Read the answer and reason

Answer: No route in this table matches · The remaining entries are 192.0.2.0/24 and 192.0.2.128/25. Neither contains 198.51.100.25, leaving no candidate.

Check, then explain in your own words

  1. Fix one table and one destination IPv4 address.
  2. List all matching entries and exclude ranges that do not contain the destination.
  3. Compare the remaining lengths and read the chosen entry’s next hop.
  4. Separate the table’s assumptions from unverified connectivity requirements.
Check your understanding: Can you select the longest entry in the whole table first?

Match the destination first, then choose the longest among the matches.

192.0.2.200 matches /0, /24 and /25, selecting B. Address 192.0.2.25 matches /0 and /24, selecting A. Address 198.51.100.25 matches only /0 in the original table, selecting C. Explain the next-hop choice separately from connectivity.

Sources and conditions checked

Primary references are collected here with their scope, conditions and corresponding sections. Independent expert review and live-environment validation have not been performed.