How Routers Work: Routing Tables, Next Hop Resolution, and Longest Prefix Match
Beginner-friendly explanation of how routers work, covering routing tables (RIB), FIB vs RIB, next hop resolution, longest prefix match, control plane vs data plane, and packet forwarding steps.
Drake Nguyen
Founder · System Architect
How routers work — a high-level overview
Understanding how routers work is essential for anyone learning networking fundamentals or studying computer networking basics. A router connects multiple IP networks and decides where to send each packet. This guide breaks down router basics like the routing table, next hop selection, and longest prefix match, with practical packet-forwarding examples. If you already know IP addressing and subnetting basics—and the OSI model vs TCP/IP model at a high level—you’ll be able to follow the logic and test it in a lab.
At a high level, routers do two jobs:
- Control plane: learns routes and decides the best path (routing fundamentals).
- Data plane (forwarding plane): forwards packets quickly using a precomputed table.
Routing tables and how they’re built
A routing table is the router’s list of known destination prefixes and the associated forwarding instructions. In most platforms, learned and configured routes are held in the RIB (Routing Information Base). After the route selection process chooses the best path per prefix, the device programs the FIB (Forwarding Information Base)—a streamlined structure used for fast forwarding.
How routing tables are built: connected, static, and dynamic routes
Routes typically enter the RIB from a few sources:
- Connected routes (directly attached subnets on an up/up interface).
- Static routes (manually configured destinations and next hops).
- Dynamic routing protocols (learned via OSPF, BGP, RIP, or others).
Route selection process (administrative distance, metrics
If multiple sources advertise a path to the same destination, the route selection process decides which route becomes active (installed as the best route). Generally, routers prefer:
- Lowest administrative distance (trustworthiness of the source; often static vs dynamic routing basics show up here).
- Lowest metric within the same protocol (e.g., hop count in RIP, cost in OSPF, attributes in BGP).
- Tie-breakers that are platform/protocol-specific if the above are still equal.
Default route and when it’s used
A default route (0.0.0.0/0) is the fallback route used when no more specific prefix matches the destination. It’s common at the network edge (toward an ISP) or in small networks where “everything else” should go to a single upstream gateway. In packet forwarding steps, the default route prevents drops for unknown destinations—assuming upstream connectivity exists.
Next hop and forwarding decisions
The next hop is the immediate router or gateway IP address a packet should be sent to on its way to the final destination. The forwarding decision uses the FIB to pick an egress interface and next hop, then performs next-hop resolution to map that next hop to a Layer 2 address (ARP for IPv4, NDP for IPv6). This is a core part of forwarding.
Next-hop resolution example (ARP and ARP table role
Example: Router A has a route to 10.1.2.0/24 via next hop 10.1.1.2 out Gig0/0. To transmit on Ethernet, Router A needs the destination MAC address for 10.1.1.2. It checks its ARP table:
# show arp (example)
10.1.1.2 00:11:22:33:44:55 Gig0/0
If there’s no entry, it broadcasts an ARP request, learns the reply, updates the ARP table, and then forwards the packet. On edge devices, NAT and port forwarding can change L3/L4 headers, but the L2 requirement remains the same: the next hop must resolve to a reachable neighbor on the local link.
Longest prefix match explained
What is longest prefix match? It’s the rule routers use to pick the most specific route that matches a destination IP. “Most specific” means the route with the largest prefix length (longest netmask) among all matching routes. Longest prefix match is what ensures traffic uses a precise internal route (like a /24) instead of a broader summary (like a /16) when both exist.
Step-by-step match example (multiple prefixes and tie-breakers
Assume these prefixes exist (in the routing table/RIB, and the best of them is programmed into the FIB):
192.168.0.0/16via R1192.168.1.0/24via R2192.168.1.128/25via R3
Destination: 192.168.1.130
All three routes match, but the router selects 192.168.1.128/25 because /25 is the longest prefix match. If two matching routes have the same prefix length (e.g., two different /24s learned from different sources), then administrative distance/metric and protocol tie-breakers determine which one is active.
Control plane vs data plane (RIB vs FIB) — where decisions happen
The control plane is where the router learns routes and computes best paths. It runs routing protocols (like OSPF, BGP, RIP), processes static configuration, and maintains the RIB. The data plane is where packets are forwarded at high speed. It uses the FIB (and adjacency/neighbor information) to forward without re-running routing calculations for every packet.
FIB vs RIB — what they store and how they’re used at runtime
Think of the RIB as the full set of candidate routes plus attributes (sources, metrics, and policy results). The FIB is the runtime-ready subset containing the selected prefix, egress interface, and next-hop information used for forwarding. When a packet arrives, the data plane performs a longest prefix match lookup in the FIB and then executes the necessary packet-forwarding steps.
Static vs dynamic routing basics (brief intro to OSPF/BGP/RIP
Static routing uses manually configured routes (for example, ip route entries). It’s straightforward and predictable but doesn’t automatically adapt to failures. Dynamic routing protocols learn and update routes as the topology changes:
- RIP: distance-vector; metric is hop count.
- OSPF: link-state; metric is cost based on interface attributes.
- BGP: path-vector; uses policy and path attributes for Internet-scale routing.
For how routers work for beginners, start with connected routes and a couple of static routes, then add OSPF in a small lab before diving into BGP behavior and policy.
Packet forwarding steps — from ingress to egress (practical flow
- Ingress: a packet arrives; the router validates basic headers and applies ACL/QoS features if configured.
- Lookup: the data plane queries the FIB and applies longest prefix match to find the best destination prefix.
- Next hop: the router identifies the next hop and performs next-hop resolution (ARP/NDP) if needed.
- Rewrite/encapsulate: decrement TTL/hop limit, update checksums as required, apply NAT if configured, and encapsulate for the egress medium.
- Egress: transmit the frame out the selected interface toward the next hop.
Common troubleshooting tips and best practices for beginners
- Inspect the routing table/RIB:
show ip route(vendor) orip route show(Linux). - Confirm the FIB/forwarding view (if available): platform-specific “show forwarding” commands help verify what’s actually programmed.
- Verify next hop reachability: ping the next-hop IP and check for L2 issues.
- Check ARP/NDP neighbor state:
show arp,arp -a, or IPv6 neighbor commands. - Validate interfaces and ACLs: down links, wrong VLANs, or filters commonly break forwarding.
- Use traceroute: visualize hop-by-hop routing and identify where packets stop.
FAQ
What is a routing table and how is it different from a forwarding table?
A routing table is typically represented by the RIB, which contains learned and configured routes plus attributes. A forwarding table is typically the FIB, which contains the selected best routes and next-hop/interface data optimized for fast lookup in the data plane.
What does next hop mean and how does a router determine it?
The next hop is the immediate destination (usually another router) that receives the packet next. The router determines it from the matching FIB entry for the destination prefix, then resolves that next hop to a MAC address via ARP (IPv4) or NDP (IPv6) before sending.
What is the longest prefix match and why is it important?
Longest prefix match ensures the router chooses the most specific available route (for example, a /25 over a /24, or a /24 over a /16). This prevents traffic from taking overly broad routes when a more precise path exists.
Conclusion — How routers work: key takeaways and next steps
How routers work comes down to a consistent flow: the control plane learns routes into the RIB, selects best paths, and programs the FIB; then the data plane uses longest prefix match, next-hop resolution, and forwarding logic to move packets from ingress to egress. To build confidence, practice reading a routing table, identifying the active route, and tracing packet forwarding steps in a small lab topology.
Appendix / Cheat sheet (commands and quick glossary
Common commands to view routing and forwarding state
- View routing table (RIB):
show ip route,ip route show - View neighbors:
show arp,arp -a(IPv4); NDP/neighbor equivalents for IPv6 - Test path:
ping,traceroute
Quick glossary
- RIB: routing information base (control plane route database).
- FIB: forwarding information base (data plane lookup table).
- Next hop: the immediate gateway used to reach a destination prefix.
- Longest prefix match: selection of the most specific matching route.
Netalith. In summary, a strong how routers work strategy should stay useful long after publication.