Week 4IP Connectivity35 min

Longest Prefix Match

Learning objectives

  • Apply longest prefix match to routing decisions
  • Compare overlapping routes and why specificity wins
  • Relate prefix length to subnet design and summarization
  • Resolve exam scenarios with multiple matching routes

Watch first

Recommended video

Dynamic Routing, AD & Floating Static (Day 24)

Video credit: Jeremy's IT Lab

Watch on YouTube

Plain-English explanation

When multiple routes match a destination IP, the router picks the most specific match — the route with the longest prefix length (most network bits). This is longest prefix match (LPM) and it drives every forwarding decision.

Example: routes for 10.0.0.0/8 and 10.1.0.0/16. Destination 10.1.1.50 matches both — /16 wins because it is longer (more specific).

Deep dive

Matching rule: Compare destination IP to each route's network + mask. Collect all matches. Choose highest prefix length. Tie-breakers: lower AD, then metric (protocol-specific).

| Destination | Routes in table | Winner | |-------------|-----------------|--------| | 10.1.1.50 | 10.0.0.0/8, 10.1.0.0/16 | 10.1.0.0/16 | | 192.168.1.100 | 192.168.0.0/16, 192.168.1.0/24, default | 192.168.1.0/24 | | 8.8.8.8 | default only | 0.0.0.0/0 |

Default route is shortest match (/0) — catches only what nothing else matches.

Summarization interaction: Upstream routers may have one summary route while downstream has specifics — LPM ensures traffic follows the detailed path where present.

Step-by-step — exam scenario

Routing table on R1:

S    10.0.0.0/8 via 1.1.1.1
O    10.1.0.0/16 via 2.2.2.2
C    10.1.2.0/24 is directly connected
S*   0.0.0.0/0 via 3.3.3.3

Where does 10.1.2.75 go? Matches /8, /16, /24 — connected /24 wins (longest).

Where does 10.2.0.1 go? Matches /8 only → via 1.1.1.1.

Where does 172.16.1.1 go? Only default → 3.3.3.3.

Commands to know

Verify specific lookup

show ip route 10.1.2.75 show ip route longer-prefixes 10.1.0.0

Troubleshooting

| Issue | LPM angle | |-------|-----------| | Traffic wrong path | More specific route elsewhere in table | | Summary blackhole | Specific route missing downstream | | Default catches internal traffic | Missing specific routes — design error |

When adding routes, ask: "Is there already a more specific match?"

Exam relevance

Exam trap

A /8 and /24 both match — always pick /24. Prefix number larger = longer match = more specific.

AD vs LPM

LPM picks candidates first among routes in the table at same AD level. If two routes same prefix length, lower AD wins.

Practice checklist

  • Given five routes, determine forwarding for ten destinations
  • Explain why default route is last resort logically
  • Design two overlapping static routes and predict behavior
  • Use show ip route [ip] to confirm LPM on lab router
  • Connect LPM to subnetting skills from Week 2

Destination 10.1.5.10 matches routes 10.0.0.0/8 and 10.1.0.0/16. Which is used?

Which prefix length is the most specific?

Video credits

These are free, open educational videos from independent creators. We link and embed them with attribution; all rights belong to the respective channels.