← Lessons

quiz vs the machine

Platinum1640

Networking

Longest Prefix Match Routing

See how a router picks among overlapping routes by choosing the most specific one.

5 min read · advanced · beat Platinum to climb

Many Routes One Destination

A router holds a routing table of network prefixes, each pointing to a next hop. A single destination address often matches several entries at once, so the router needs a rule to choose.

The Rule Of Specificity

The router applies longest prefix match: among all entries whose prefix contains the destination, it picks the one with the longest prefix length, meaning the most specific network.

  • A default route matches everything but is the least specific.
  • A wider prefix covers a large block of addresses.
  • A narrower prefix covers a small block and wins when it matches.

A more specific route therefore overrides a broader one for the addresses it covers.

Why This Matters

Longest prefix match lets networks express both broad defaults and precise exceptions in one table.

  • A provider can route a whole region with one wide prefix.
  • A single customer block can be steered differently with a narrow prefix.
  • The default route catches anything no specific entry covers.

In Practice

Routers use specialized data structures so this lookup runs fast even with hundreds of thousands of routes. The result is a consistent, predictable choice for every packet regardless of how many entries overlap.

Key idea

When several routes match a destination, longest prefix match selects the most specific prefix, letting one table hold broad defaults and precise exceptions together.

Check yourself

Answer to earn rating on the learn ladder.

1. When several routes match a destination, which one does a router choose?

2. What role does the default route play?