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.
List every matching entry in one fictional IPv4 table, then explain the longest matching prefix and its next hop.
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.
| Destination prefix | Next-hop label | Given state |
|---|---|---|
| 0.0.0.0/0 | C | Available |
| 192.0.2.128/25 | B | Available |
| 192.0.2.0/24 | A | Available |
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.
- Destination IP → All matching entriesRetain ranges containing the destination
- All matching entries → Longest matchCompare lengths only among matches
- 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
| Prefix | First address | Last address | Total addresses |
|---|---|---|---|
| 192.0.2.0/24 | 192.0.2.0 | 192.0.2.255 | 256 |
| 192.0.2.128/25 | 192.0.2.128 | 192.0.2.255 | 128 |
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.
- 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
| Destination IP | All matching lengths | Selected prefix | Next hop |
|---|---|---|---|
| 192.0.2.200 | /0, /24, /25 | 192.0.2.128/25 | B |
| 192.0.2.25 | /0, /24 | 192.0.2.0/24 | A |
| 198.51.100.25 | /0 | 0.0.0.0/0 | C |
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.
Check, then explain in your own words
- Fix one table and one destination IPv4 address.
- List all matching entries and exclude ranges that do not contain the destination.
- Compare the remaining lengths and read the chosen entry’s next hop.
- 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.
Scope and conditionsSection 5.2.4.3: Basic Match before Longest Match and further selection conditions. Limited to three supplied available IPv4 entries; no universal OS, policy, route-learning or live-traffic validation. Updates 2644/6633 and all-status errata were screened against these claims.
Used in this lessonUse only these three available routes Match the destination before comparing lengths Compare the matching set for three destinations Separate route selection from evidence of connectivity
Scope and conditionsSections 3.1/5/5.1: prefix and length, longest-match forwarding and 0.0.0.0/0. Aggregation, route advertisement and filter implementation are outside scope. Do not reuse the diagram corrected by erratum 2955; ranges and complete matching sets are separately calculated.
Used in this lessonMatch the destination before comparing lengths Read why /25 is more specific than /24 Compare the matching set for three destinations
Scope and conditionsSections 3/4: documentation blocks, including 192.0.2.0/24; not live targets or local configuration.
Used in this lessonUse only these three available routes