Forwarding Table & Longest-Prefix Match
Read this concept as one more decision made about a packet in flight. The widget below lets you change the inputs and watch the consequence instead of memorising the rule.
Why it matters
A router usually has several prefixes containing the same destination, and it must pick the most specific one rather than the first entry in the table. This rule is what lets default routes and exceptions coexist.
On the wire
For a destination address, the router ANDs it with each stored mask and compares the result to the stored prefix, then selects the entry with the longest matching bit count. A default route of 0.0.0.0/0 matches everything but loses to any more specific entry.
When it breaks
A missing specific route sends traffic toward the default gateway, which may black-hole it or send it back out the same interface. A stale entry with a longer prefix can override a correct route learned later, so packets follow an outdated path even though the table looks healthy.
Forwarding lookup
Pick a destination, then click table rows to disable a route and watch longest-prefix matching react.
| Prefix | Next hop | Metric | State |
|---|---|---|---|
| 0.0.0.0/0 | 100 | matches | |
| 203.0.113.0/24 | 10 | no match | |
| 203.0.113.128/25 | 10 | no match |
0.0.0.0/0 wins with /0: Matches everything, least specific.