Loading learning content...
When you request a webpage from a server halfway around the world, your data doesn't travel in a straight line. It hops through perhaps 15-20 routers, each one making a decision: "Given where this packet needs to go, what's the best next step?"
These decisions happen billions of times per second across millions of routers worldwide. Each decision must be made in microseconds. And somehow, despite the Internet's vast complexity—with networks constantly failing, recovering, congesting, and changing—packets almost always find their way.
Routing is the network layer function responsible for this remarkable feat. It encompasses:
This page introduces routing concepts at the network layer level. Subsequent chapters will explore specific routing protocols (RIP, OSPF, BGP) in exhaustive detail.
By the end of this page, you will understand the fundamental distinction between routing and forwarding, how routing tables are structured and used, the difference between static and dynamic routing, the categories of routing algorithms (distance vector, link state, path vector), and why routing at Internet scale is one of computing's greatest engineering achievements.
Before diving into routing mechanisms, we must distinguish two related but fundamentally different network layer functions that are often confused: routing and forwarding.
Forwarding (Data Plane):
Forwarding is the per-packet operation of moving a packet from input to output:
Forwarding happens for every packet and must be extremely fast—modern routers forward billions of packets per second. Forwarding is implemented in specialized hardware (ASICs, FPGAs) in high-end routers.
Routing (Control Plane):
Routing is the network-wide process of determining paths:
Routing happens in the background—not per-packet, but periodically or when topology changes. Routing is implemented in software, running on the router's general-purpose CPU.
| Aspect | Routing (Control Plane) | Forwarding (Data Plane) |
|---|---|---|
| Frequency | Periodic or event-driven | Per packet |
| Speed Required | Seconds to minutes acceptable | Microseconds required |
| Implementation | Software (general CPU) | Hardware (ASICs/TCAMs) |
| Scope | Network-wide process | Local to each router |
| Function | Compute and populate tables | Use tables to forward packets |
| Complexity | Complex algorithms, protocols | Simple table lookup |
| Failure Impact | Routes may be suboptimal | Packets dropped or lost |
The Relationship:
Routing Process Forwarding Process
│ │
├─→ Routing Table ─→ Forwarding Table ─→ Packet Switching
│ │ │
│ │ └─→ Outgoing Interface
│ │
│ └─→ Next Hop IP/Interface for each prefix
│
└─→ Routing Protocols (OSPF, BGP, etc.)
Routing produces the knowledge ("how do I reach this network?"); forwarding uses that knowledge for each packet ("which port does this packet exit?").
Routing is planning the trip; forwarding is driving each mile. You plan a route once (using maps and traffic data), but you make individual driving decisions at every intersection based on that plan. Similarly, routing computes paths; forwarding acts on them for each packet.
The routing table is the data structure that stores the router's knowledge about how to reach destination networks. Understanding its structure is fundamental to understanding how routing works.
Core Routing Table Fields:
Every routing table entry contains (at minimum):
| Field | Purpose | Example Value |
|---|---|---|
| Destination Prefix | Network address and prefix length to match | 10.45.0.0/16 |
| Next Hop | IP address of the next router toward destination | 192.168.1.1 |
| Outgoing Interface | Physical/logical interface to transmit on | eth0, GigE0/1 |
| Metric/Cost | Measure of route quality (lower is better) | 10, 100, 65535 |
| Route Type | Source of this routing information | Connected, Static, OSPF, BGP |
| Administrative Distance | Preference when multiple protocols provide routes | 0-255 (lower preferred) |
Example Routing Table (Simplified):
Destination Next Hop Interface Metric Type
----------- -------- --------- ------ ----
0.0.0.0/0 203.0.113.1 eth0 1 Static
10.0.0.0/8 192.168.1.1 eth1 10 OSPF
10.45.0.0/16 192.168.1.2 eth1 5 OSPF
172.16.5.0/24 192.168.2.254 eth2 20 BGP
192.168.1.0/24 0.0.0.0 eth1 0 Connected
192.168.2.0/24 0.0.0.0 eth2 0 Connected
Route Types Explained:
Connected Routes: Networks directly attached to the router's interfaces. Next hop is 0.0.0.0 or implicit—packets are delivered directly.
Static Routes: Manually configured by administrators. Simple but don't adapt to failures.
Dynamic Routes: Learned from routing protocols (OSPF, RIP, BGP, etc.). Automatically adapt to network changes.
Default Route: 0.0.0.0/0 matches everything. Used when no more specific route exists—"gateway of last resort."
Longest Prefix Match:
When multiple entries match a destination, the router selects the one with the longest prefix (most specific match):
Destination IP: 10.45.99.50
0.0.0.0/0 → Matches (0 bits)
10.0.0.0/8 → Matches (8 bits)
10.45.0.0/16 → Matches (16 bits) ← SELECTED
This enables hierarchical routing: more specific routes override more general ones.
In large routers, the routing table (maintained by software, with all learned routes) is separate from the forwarding table (a hardware-optimized subset installed in fast lookup hardware). The routing process selects the best routes and installs them in the forwarding table. This separation allows routing computation without affecting forwarding speed.
Routes can be configured manually (static) or learned automatically (dynamic). Each approach has distinct advantages and trade-offs.
Static Routing:
Administrators manually configure routes on each router:
# Cisco IOS
ip route 10.45.0.0 255.255.0.0 192.168.1.1
# Linux
ip route add 10.45.0.0/16 via 192.168.1.1
Dynamic Routing:
Routers run routing protocols that automatically:
When to Use Each:
| Scenario | Recommended Approach |
|---|---|
| Small network, simple topology | Static routes often sufficient |
| Stub network (single exit point) | Static default route |
| Complex topology with redundancy | Dynamic routing essential |
| Internet backbone | Dynamic routing (BGP) mandatory |
| Enterprise core | Dynamic routing (OSPF/IS-IS) |
| Single-homed home network | Static default route |
| Multi-homed enterprise | Dynamic routing for failover |
Hybrid Approaches:
Most real networks use both:
Static routes don't automatically deactivate when links fail (unless configured with monitoring). A static route pointing to a down next-hop becomes a "black hole" that silently drops packets. Dynamic routing protocols detect failures and remove affected routes automatically.
Dynamic routing protocols use algorithms that fall into three major categories, each with distinct approaches to learning topology and computing paths.
1. Distance Vector Algorithms
Based on the Bellman-Ford algorithm, distance vector protocols share routing tables with neighbors:
Distance Vector Operation:
Router A knows: Router B knows:
Network X: cost 2 Network X: cost 5
Network Y: cost 4 Network Y: cost 1
A tells B: "I can reach X with cost 2"
B calculates: Via A, cost to X = link_cost(B→A) + 2
If this is better than 5, B updates its table
2. Link State Algorithms
Based on Dijkstra's SPF (Shortest Path First) algorithm, link state protocols share link information:
Link State Operation:
Each router floods Link State Advertisements (LSAs):
Router A: "I have links to B (cost 1), C (cost 3)"
Router B: "I have links to A (cost 1), C (cost 2), D (cost 1)"
...
Every router builds complete graph.
Each runs Dijkstra to compute shortest paths to all nodes.
Result: All routers agree on shortest paths (consistent routing).
3. Path Vector Algorithms
Designed for inter-domain routing, path vector protocols share complete path information:
Path Vector Purpose:
Path vector is used for routing between organizations (Autonomous Systems). It enables:
| Characteristic | Distance Vector | Link State | Path Vector |
|---|---|---|---|
| Information Exchanged | Distance to destinations | Link states (topology) | Complete AS paths |
| Topology Knowledge | None (distances only) | Complete | Path-level only |
| Algorithm | Bellman-Ford | Dijkstra SPF | Policy-based selection |
| Convergence | Slow (iterative) | Fast (flood-then-compute) | Moderate |
| Scalability | Limited | Good within domain | Excellent between domains |
| CPU/Memory | Low | High (stores topology) | Moderate |
| Loop Prevention | Split horizon, poison reverse | Inherent (SPF) | AS path checking |
| Typical Use | Small/legacy networks | Enterprise/ISP internal | Internet backbone |
Link state protocols are dominant for intra-domain routing (within organizations) because they converge faster and scale better. Path vector (BGP) is the only option for inter-domain routing because it supports the policy decisions required when different organizations interconnect. Distance vector protocols like RIP are legacy but still encountered in simple or educational contexts.
When multiple paths to a destination exist, routers must choose. Routing metrics provide a quantitative basis for this choice—they measure the "cost" or "quality" of a path.
Common Routing Metrics:
| Metric | Measures | Lower Is Better? | Used By |
|---|---|---|---|
| Hop Count | Number of routers traversed | Yes | RIP |
| Bandwidth | Link capacity (bps) | No (higher better) | OSPF (configurable), EIGRP |
| Delay | Time for packet transit | Yes | EIGRP |
| Load | Current utilization percentage | Yes | EIGRP (optional) |
| Reliability | Error rate / link stability | No (higher better) | EIGRP (optional) |
| MTU | Maximum transmission unit | No (higher better) | EIGRP (tiebreaker) |
| Administrative Cost | Manually assigned preference | Yes | OSPF, IS-IS |
| AS Path Length | Number of AS hops | Yes | BGP |
Hop Count:
The simplest metric—count how many routers the packet must traverse:
Path A: Source → R1 → R2 → Destination (2 hops)
Path B: Source → R3 → Destination (1 hop)
→ Path B preferred (fewer hops)
Limitation: Doesn't account for link speed. A path with 2 hops over Gigabit Ethernet is far faster than 1 hop over a 56 Kbps dialup link.
Bandwidth-Based Metrics:
OSPF (by default) uses a cost inversely proportional to bandwidth:
$$\text{OSPF Cost} = \frac{\text{Reference Bandwidth}}{\text{Interface Bandwidth}}$$
With a reference of 100 Mbps:
Composite Metrics:
EIGRP computes a sophisticated metric combining multiple factors:
$$\text{EIGRP Metric} = 256 \times \left( K_1 \times \text{Bandwidth} + \frac{K_2 \times \text{Bandwidth}}{256 - \text{Load}} + K_3 \times \text{Delay} \right) \times \left( \frac{K_5}{\text{Reliability} + K_4} \right)$$
By default, only $K_1$ (Bandwidth) and $K_3$ (Delay) are used, simplifying to:
$$\text{Metric} = 256 \times \left( \frac{10^7}{\text{Bandwidth}_{min}} + \sum{\text{Delays}} \right)$$
where Bandwidth is in kbps and Delay is in tens of microseconds.
In practice, administrators often override automatic metrics to implement routing policy. Setting a higher OSPF cost on a link forces traffic to prefer other paths, even if the link is technically faster. This manual tuning is common for load balancing, preferring primary over backup links, and compliance requirements.
The Internet's routing architecture divides the world into Autonomous Systems (ASs)—networks under a single administrative control. Routing operates differently within and between these domains.
Autonomous System (AS):
An AS is a collection of IP networks under a single organization's control with a unified routing policy:
Two Routing Scopes:
Interior Gateway Protocols (IGPs) — Intra-Domain:
IGPs operate within a single AS:
Exterior Gateway Protocols (EGPs) — Inter-Domain:
EGPs operate between ASs:
| Aspect | IGP (Intra-Domain) | EGP (Inter-Domain) |
|---|---|---|
| Scope | Single Autonomous System | Between Autonomous Systems |
| Trust Model | Full trust between routers | Limited trust, policy-based |
| Path Selection | Shortest/fastest path | Policy-preferred path |
| Metrics | Technical (bandwidth, delay) | AS path, policy attributes |
| Scale | Hundreds to thousands of routers | Millions of prefixes, ~80,000 ASs |
| Convergence | Seconds | Minutes (intentionally slow) |
| Examples | OSPF, IS-IS, EIGRP, RIP | BGP |
BGP (Border Gateway Protocol) is arguably the most critical protocol on the Internet. It's how every ISP learns about every other network on the planet. BGP misconfigurations can—and have—caused global Internet outages. BGP security (RPKI, BGPsec) is an active area of development because BGP was designed in a more trusting era.
When network topology changes—a link fails, a new route appears, a cost changes—routing protocols must update their tables. Convergence is the process of all routers reaching a consistent, up-to-date view of the network.
Convergence Timeline:
Convergence Time Matters:
During convergence:
Faster convergence = shorter outage duration.
Factors Affecting Convergence Speed:
Convergence Problems:
Routing Loops During Convergence:
Before failure: A → B → C → Destination
Link B→C fails.
A still thinks: B is the path
B knows: C is unreachable, but maybe A knows another path?
B sends to A: "Try reaching destination!"
A sends back to B: "Sure, via you!"
→ Packet loops between A and B until TTL expires
Count-to-Infinity (Distance Vector):
In distance vector protocols, routers may slowly increment metrics until reaching "infinity":
A → B → C (B→C fails)
A thinks: Distance to C = 2 (via B)
B knows: C unreachable
B hears from A: "C is distance 2"
B thinks: Maybe I can reach C via A! Cost = 3
B tells A: "C is distance 3"
A thinks: Cost is now 4
... continues until metric reaches infinity (16 in RIP)
Mitigations:
Modern networks aim for sub-second convergence. Techniques include: BFD for millisecond failure detection, fast reroute (pre-computed backup paths), IP FRR (loop-free alternates), and careful timer tuning. For critical applications, even 50ms of packet loss can cause noticeable impact (VoIP, video, financial trading).
Routing is what turns a collection of individual networks into the Internet—a globally interconnected system where any host can reach any other. Let's consolidate the key insights:
What's Next:
Routing determines paths; but once a path is determined, packets must actually be moved hop-by-hop. The next page covers packet handling—the operations routers perform on each packet: header processing, TTL management, fragmentation, and the forwarding decision itself.
You now understand routing—the network layer function that discovers and selects paths through the internetwork. The distinction between routing and forwarding, the structure of routing tables, the choice between static and dynamic routing, the major algorithmic approaches, and the importance of convergence—all form the foundation for deeper study of specific protocols like OSPF and BGP in later chapters.