In the complex architecture of modern networking, a router is often compared to a sophisticated air traffic controller. To manage the vast flow of data, it relies on a critical internal database known as the Routing Information Base (RIB).
The RIB is the master repository where a router stores all prefix information learned from various sources, including static configurations and dynamic protocols. However, the RIB is not the same as the Forwarding Information Base (FIB)—the actual table used to switch packets. Instead, the RIB acts as the decision-making engine that filters through competing routes to select the singular best path for any given destination.
Table of Contents
- The Hierarchy of Route Selection
- Deep Dive: The BGP Best Path Algorithm
- RIB vs. FIB: From Decision to Action
- Summary of Key Takeaways
- Sources
The Hierarchy of Route Selection
When a router receives multiple paths to the same destination, it doesn’t simply pick one at random. It follows a strict, standardized hierarchy to ensure the chosen path is the most reliable and efficient.
1. The Longest Prefix Match (The Golden Rule)
The first and most important rule in path selection is the Longest Prefix Match (LPM). According to Cisco, routers prioritize the most specific route over a more general one [1].
For example, if the RIB contains two entries:
10.1.1.0/24
10.1.0.0/16
A packet destined for 10.1.1.5 will always follow the /24 route because it is more specific. As noted by Study-CCNP, this logic can be used by network administrators to influence traffic flow by advertising more specific subnets to preferred entry points [2].
2. Administrative Distance (Protocol Trustworthiness)
If the router has two identical prefix lengths (e.g., two routes for 192.168.1.0/24) learned from different sources, it uses Administrative Distance (AD) to break the tie. AD is a measure of “trustworthiness” assigned to a routing source.
Lower AD values are preferred. Typical default values include:
Connected Interface: 0
Static Route: 1
eBGP: 20
OSPF: 110
RIP: 120
If you are building a resilient network, understanding these values is as vital as choosing the best computer hardware for your server room; the hardware provides the power, but the AD provides the logic.
| Routing Source | Standard AD Value |
|---|---|
| Connected Interface | 0 |
| Static Route | 1 |
| eBGP | 20 |
| OSPF | 110 |
| RIP | 120 |
3. Metric (The Tie-Breaker)
If the prefix length and the AD are identical (e.g., two different paths learned via the same OSPF process), the router compares the Metric. Each protocol calculates its metric differently:
RIP uses hop count.
OSPF uses cost (based on bandwidth).
EIGRP uses a complex formula involving bandwidth and delay.
The RIB selects the path with the lowest metric to be installed as the “Best Path” in the forwarding table.
The Longest Prefix Match (LPM) is the ultimate authority in route selection. Regardless of the routing protocol or administrative distance, the router will always prefer the more specific route (the one with the longer prefix length) for a destination.
If the prefix lengths are identical, the router uses Administrative Distance (AD) to determine which source is more trustworthy. A lower AD value is preferred, meaning a Static Route (AD 1) will typically be chosen over an OSPF route (AD 110).
A Metric is used as a final tie-breaker when a router has multiple paths to the same destination with identical prefix lengths and identical Administrative Distances. This usually occurs when a single protocol, like OSPF or EIGRP, finds multiple paths to the same network.
Deep Dive: The BGP Best Path Algorithm
The Border Gateway Protocol (BGP) is unique because it doesn’t use a simple metric like hop count. Instead, it uses a sequence of attributes to determine the best path. According to NetworkLessons, BGP evaluates attributes in a specific order until a tie is broken [3]:
- Weight: A Cisco-proprietary attribute local to the router (highest is preferred).
- Local Preference: Used to tell the AS how to exit (highest is preferred).
- Originate: Locally originated routes are preferred over learned ones.
- AS_Path Length: The path that crosses the fewest autonomous systems [4].
- Multi-Exit Discriminator (MED): Used to suggest to external neighbors which path to take into your AS (lowest is preferred).
This granular control is why BGP is the backbone of the internet, allowing for sophisticated traffic engineering that internal protocols cannot match.
BGP manages routing on a global scale across different organizations, requiring more granular control. Attributes like Weight, Local Preference, and AS_Path allow administrators to engineer traffic flow based on business policies rather than just the shortest physical path.
Local Preference is used to influence how traffic leaves your own Autonomous System (AS). In contrast, the Multi-Exit Discriminator (MED) is an attribute sent to external neighbors to suggest which path they should take when entering your AS.
RIB vs. FIB: From Decision to Action
Once the RIB has finished its calculations, it “vets” the best routes and pushes them to the Forwarding Information Base (FIB) and the Adjacency Table.
While the RIB is optimized for complexity and management, the FIB is optimized for speed. In high-performance routers, the FIB is often stored in specialized hardware called TCAM (Ternary Content-Addressable Memory), which allows for near-instantaneous lookups. This transition from software-based logic to hardware-accelerated forwarding is a cornerstone of secure network programming, ensuring that security policies are applied at line rate without slowing down traffic.
The Routing Information Base (RIB) is the ‘brain’ where complex path calculations and protocol comparisons happen in software. The Forwarding Information Base (FIB) is the ‘brawn,’ a mirrored table optimized for high-speed hardware lookups to move packets as quickly as possible.
Ternary Content-Addressable Memory (TCAM) allows for near-instantaneous, parallel lookups of the entire routing table. This hardware acceleration ensures that routing decisions do not become a bottleneck, allowing the router to forward traffic at line rate.
Summary of Key Takeaways
Longest Prefix Match is the ultimate authority; a more specific route always wins, regardless of the protocol or metric.
Administrative Distance determines which routing protocol to trust when multiple protocols deliver information about the same network.
Metrics serve as the internal “cost” calculator for a specific protocol to find the most efficient route.
BGP relies on Path Attributes, such as Weight and AS_Path, rather than a single metric, allowing for global-scale traffic management.
The RIB is the Brain, the FIB is the Brawn: The RIB makes the complex decisions, while the FIB executes the forwarding at high speeds.
Action Plan for Network Administrators
- Audit Your ADs: Ensure that your floating static routes have a higher AD than your dynamic protocols to prevent routing loops or unintended paths.
- Use Specificity Strategically: If you want to force traffic through a specific link without changing metrics, advertise a more specific subnet (e.g., a /25 instead of a /24).
- Monitor RIB Failures: Use commands like
show ip bgp rib-failureon Cisco devices to identify paths that BGP wants to use but cannot because a better route from a different source already exists in the RIB. - Optimize for TCAM: Avoid over-summarization and keep your routing tables lean to stay within the hardware limits of your router’s FIB capacity.
By mastering the logic of the RIB, you move from simply “connecting” networks to “engineering” them for maximum uptime and performance.
| Selection Level | Primary Criteria | Purpose |
|---|---|---|
| Rule 1 | Longest Prefix Match | Prioritizes the most specific destination match. |
| Rule 2 | Administrative Distance | Selects the most trustworthy protocol source. |
| Rule 3 | Metric | Tie-breaker based on paths within a protocol. |
| Hardware | FIB / TCAM | High-speed, hardware-accelerated packet forwarding. |
Administrators can advertise a more specific subnet, such as a /25 instead of a /24. Because of the Longest Prefix Match rule, routers will always prioritize the more specific advertisement, effectively steering traffic toward that preferred entry point.
Check for ‘RIB failures’ using device-specific commands like ‘show ip bgp rib-failure’. This often happens when BGP identifies a valid path, but another protocol with a lower Administrative Distance already has a better route to that destination in the RIB.