How Routers Make Decisions: Routing Tables and BGP
Imagine you're driving across the country without a map or a GPS. You arrive at a major highway intersection. There are signs pointing in different directions: North, South, East, West. You know your destination is "Seattle," but the signs only point to the next immediate towns. You have to ask the toll booth operator which road to take. The operator doesn't know how to get to Seattle either, but they know the Westward road gets you closer. You take it. At the next intersection, you ask again.
This is exactly how data travels across the internet.
A packet of data doesn't contain a map. It only contains its final destination (the IP address). Every time the packet arrives at a router, that router has to make a split-second decision: "Out of all the cables plugged into me, which one gets this packet closer to its final destination?"
This process is called routing. It is the core function of the internet. And the mechanism behind it—how routers learn the roads and choose the best paths—is a fascinating mix of algorithmic efficiency and human politics.
The Routing Table: A Router's Brain
Inside every router is a database called a Routing Table.
A routing table is essentially a list of rules. Each rule says: "If a packet is destined for Network X, send it out of Interface Y."
When a packet arrives, the router inspects the destination IP address, scans its routing table for the best match, and immediately forwards the packet out the designated port. This lookup happens in microseconds, millions of times a second.
For your home router, the routing table is incredibly simple. It basically has two rules:
1. If the destination is on the local home network (e.g., 192.168.1.x), send it to the local switch.
2. If the destination is literally anything else, send it out the WAN port to the Internet Service Provider (ISP). This is called the Default Route. Your router doesn't need to know the entire internet; it just passes the buck to the ISP.
But when your packet reaches an ISP's core router, things get vastly more complicated. An ISP router might be connected to a dozen other massive networks. It can't just pass the buck. It has to know exactly which of those dozen paths is the most efficient route to reach a server in Japan, or a data center in Brazil, or a mobile phone on the other side of town.
How does an ISP router learn all these paths? It talks to other routers.
Dynamic Routing: Routers Gossiping
In the early days of networking, administrators used to type routing tables by hand. If a new cable was plugged in, a human had to update the router. Today, with the internet constantly shifting, cables breaking, and new networks coming online, manual configuration is impossible.
Instead, routers use Routing Protocols to dynamically discover paths. They essentially gossip with their neighbors.
Router A might say to Router B: *"Hey, I know how to reach Networks X, Y, and Z. It takes me this much effort to get there."*
Router B records this in its table and then tells Router C: *"Hey, if you need to reach Networks X, Y, or Z, you can send the traffic through me. I know a guy."*
Within a single organization's network (like a university campus or a corporate intranet), routers use Interior Gateway Protocols like OSPF (Open Shortest Path First). OSPF is highly mathematical. Routers share a complete map of the internal network, assign a "cost" to every link based on bandwidth and speed, and run complex algorithms to mathematically prove the absolute fastest, shortest path from point A to point B.
But OSPF only works when all the routers are owned by the same people and trust each other completely. The internet as a whole is not owned by one entity. It is a loose federation of thousands of competing ISPs, corporations, and governments. They don't trust each other, and they certainly don't want to share a single, unified map of their internal infrastructure.
To route data *between* these competing networks, the internet relies on a very different beast.
BGP: The Protocol That Runs the Internet
The internet is divided into thousands of independent networks called Autonomous Systems (AS). Comcast is an AS. Google is an AS. The University of Oxford is an AS.
To exchange traffic, these Autonomous Systems use the Border Gateway Protocol (BGP).
If OSPF is a GPS calculating the shortest physical distance, BGP is a business negotiation. BGP does not care about the fastest or shortest path. BGP cares about policies, agreements, and money.
When AT&T's routers talk to Verizon's routers using BGP, they don't just say, "Here are the networks I know." They use complex rules to dictate *how* traffic should flow based on business contracts.
For example, an ISP might configure its BGP routers with rules like:
Because BGP relies entirely on trust between network administrators, it is famously fragile.
When BGP Breaks
When a network administrator makes a typo in a BGP configuration, it can break the internet.
A famous example occurred in 2008 when the government of Pakistan attempted to block YouTube within its own borders. They configured their local routers to say, "Send all traffic destined for YouTube's IPs to a black hole." This worked perfectly for their internal network.
However, a Pakistani ISP accidentally leaked this new routing rule out to the global BGP network. They essentially shouted to the rest of the world, "Hey, we are the best, most direct route to reach YouTube!"
Because of how BGP works, routers around the world updated their tables and started sending all of the planet's YouTube traffic to Pakistan. Pakistan's infrastructure was instantly crushed by the massive influx of data, and YouTube was knocked offline globally for two hours. This is known as a BGP Hijack.
Similar incidents happen almost every year. A small ISP in a remote country accidentally announces that they own the IP addresses for Google or Amazon, and huge swaths of global traffic are suddenly routed into the abyss.
The Chaos that Works
Routing is a miracle of decentralized engineering. There is no central authority telling data where to go. Trillions of packets are bouncing across the globe right now, navigating a maze of fiber optic cables, guided entirely by machines gossiping with each other based on trust, math, and business contracts.
It is messy, it is political, and it occasionally breaks spectacularly. But overwhelmingly, the system works.