Intermediate

Longest prefix match: why this route and not that one

A router has a broad route and a narrower route that both cover the same addresses. The most specific match wins, whatever order the routes were added in.

Open this lab

Free interactive lab. No signup. Runs in your browser.

The scenario

Client (10.0.0.10) sends everything through the Router. The Router has two static routes that overlap: 10.10.0.0/16 via 10.0.1.2 (Path-A) and 10.10.1.0/24 via 10.0.2.2 (Path-B). Behind Path-A is Server-A at 10.10.2.10; behind Path-B is Server-B at 10.10.1.10. An address like 10.10.1.10 matches both routes, because 10.10.1.0/24 sits inside 10.10.0.0/16. The Router picks the route with the longest prefix, the /24, so Server-B is reached through Path-B. Take the /24 away and the /16 catches that traffic and sends it to Path-A, which has no idea where 10.10.1.10 is. OSPF is switched off on every router, so these static routes are the only ones that exist.

What you will work out

Master longest prefix match: how a router chooses between several routes that all match a destination.

Why this matters

Every IP forwarding decision, on a home router, a cloud route table or an internet backbone router, is a longest prefix match. It is how a more specific route carves an exception out of a broad one: a /24 for one site inside a company-wide /16, or a VPN route that overrides a default route. It is also why a wrong broad route fails quietly: it sends traffic confidently to a place that cannot deliver it.

Running it

Why This Route, Not That One? opens on a canvas, already wired and addressed. Trace a packet through it hop by hop, or run the same topology live on real Linux network namespaces. How the two modes differ.

Open Why This Route, Not That One?

Runs in your browser. No install, no signup, and the simulation starts instantly.

Open the lab →