Networking · interactive
Routing: longest prefix wins
A router doesn't know the whole path, only which neighbour to send each packet to next. Its table lists address ranges; when several match, the most specific (longest prefix) wins.
packet to 10.1.2.77
| prefix | next hop | match? |
|---|---|---|
| 0.0.0.0/0 | ISP uplink (default route) | ✓ |
| 10.0.0.0/8 | Core router (all of 10.x) | ✓ |
| 10.1.0.0/16 | Office VPN (office network) | ✓ |
| 10.1.2.0/24 | Lab switch (one lab subnet) | ✓ longest |
| 192.168.0.0/16 | LAN (local devices) | – |
→ forward to Lab switch
4 routes match 10.1.2.77. /24 is the most specific, so the packet goes to Lab switch.
Destination
Step 2 of 4 · read left to right
In production
Tools and technologies
Every router and cloud network uses longest-prefix routing.
Not tied to one language — use these names when you search docs or design a system.