How Internet Routing Works: A Simplified Explanation
Introduction: The Internet's Postal Service
Imagine sending a letter across the country. You write the destination address, drop it in a mailbox, and trust the postal service to figure out the best way to get it there, passing through various sorting centers and transportation networks. Internet routing works on a remarkably similar principle, but at lightning speed and unimaginable scale.
When you browse a website, send an email, or stream a video, the data doesn't travel directly from your device to the server. Instead, it's broken down into small pieces called packets, each stamped with a destination IP address. These packets embark on a journey across a vast, interconnected network of devices called routers. Each router acts like a mini sorting center, deciding where to send the packet next to get it closer to its final destination.
This post dives deep into the mechanics of internet routing, explaining how your data finds its way across the globe.
Before the Journey: DNS and Packetization
Before routing even begins, two key things usually happen:
- DNS Lookup: When you type
www.google.com
into your browser, your computer doesn't inherently know Google's IP address. It first performs a DNS (Domain Name System) lookup. Think of DNS as the internet's phonebook. Your device queries DNS servers to translate the human-readable domain name (www.google.com
) into a machine-readable IP address (e.g.,142.250.190.78
). This IP address is the crucial destination address for your data packets. - Packetization: The data you want to send (e.g., the request to load Google's homepage) is too large to send in one go. The TCP/IP protocol suite (specifically TCP at the Transport Layer) breaks the data into smaller, numbered packets. Each packet gets headers containing information like the source IP address (your device's public IP), the destination IP address (obtained from DNS), sequence numbers (to reassemble the data later), and other control information.
Figure 1: Initial steps before routing (DNS Lookup and Packetization).
Step 1: Leaving Your Local Network
Your device (computer, phone) is connected to a local network (e.g., your home Wi-Fi). It has a private IP address (like 192.168.1.100
) only usable within that local network.
- Destination Check: Your device first checks if the destination IP address is on the same local network. If it were (e.g., printing to a network printer), it would send the packet directly.
- Default Gateway: Since the destination server (e.g., Google) is outside your local network, your device sends the packets to its configured Default Gateway. This is typically your home router (
192.168.1.1
). - NAT: Your home router performs NAT (Network Address Translation). It replaces the packet's source private IP address with your network's single public IP address (assigned by your ISP). It keeps track of this translation so return traffic can find its way back to your specific device.
The packets, now addressed with your public IP as the source and the destination server's IP as the destination, are forwarded by your router to your Internet Service Provider (ISP).
Step 2: The Router's Decision - The Core Loop
Once packets hit your ISP's network, they encounter the first of potentially many routers on the public internet. Each router performs a fundamental decision-making process:
- Packet Arrival: The router receives a packet on one of its interfaces.
- Destination IP Examination: It looks at the destination IP address in the packet's header.
- Routing Table Lookup: The router consults its internal routing table. This table is like a map or directory built and constantly updated by routing protocols.
- Finding the Best Match: The router looks for an entry in the table that matches the destination IP address. It typically looks for the most specific match (longest prefix match). For example, an entry for
142.250.190.0/24
is more specific than142.250.0.0/16
. - Forwarding Decision: Based on the matching entry, the routing table tells the router:
- Which of its outgoing interfaces to use.
- The IP address of the next router (the "next hop") to send the packet to.
- Packet Forwarding: The router sends the packet out the specified interface towards the next-hop router.
- TTL Decrement: The router usually decrements the packet's TTL (Time To Live) field. If TTL reaches zero, the packet is discarded (preventing infinite loops).
This process repeats at every router the packet encounters along its path.
Figure 2: Simplified Router Decision Process.
Step 3: Building the Maps - Routing Tables and Protocols
How does a router know where to send packets? It learns this information and builds its routing table using routing protocols.
Routing Tables
A routing table typically contains entries like:
Destination Network | Subnet Mask (or Prefix Length) | Next Hop IP Address | Interface | Metric |
---|---|---|---|---|
142.250.190.0 | 255.255.255.0 (/24) | 74.125.30.1 | eth1 | 10 |
10.0.0.0 | 255.0.0.0 (/8) | 192.168.5.1 | eth0 | 5 |
0.0.0.0 | 0.0.0.0 (/0) | 203.0.113.1 | eth2 | 100 |
- Destination Network/Mask: The network the entry applies to.
- Next Hop: The IP address of the next router to send packets for this destination.
- Interface: Which physical connection on the router leads towards the next hop.
- Metric: A cost associated with the path (e.g., hop count, bandwidth, delay). Lower is usually better.
Routing Protocols
Routers don't figure out these paths in isolation; they talk to each other using routing protocols.
- Interior Gateway Protocols (IGPs): Used within a single network or Autonomous System (AS). Examples include OSPF (Open Shortest Path First) and EIGRP (Enhanced Interior Gateway Routing Protocol - Cisco proprietary). They help routers within the same organization share detailed information about internal network topology to find the most efficient paths locally.
- Exterior Gateway Protocol (EGP): Used between different Autonomous Systems. The dominant (and essentially only) EGP used on the internet today is BGP (Border Gateway Protocol).
Step 4: Crossing Boundaries - Autonomous Systems (ASNs) and BGP
The internet isn't one single network; it's a massive network of networks. These individual networks, managed by entities like ISPs (Comcast, AT&T), cloud providers (AWS, Google Cloud), universities, or large companies, are called Autonomous Systems (AS). Each AS is assigned a unique ASN (Autonomous System Number).
- BGP Peering: Routers at the edges of different ASes (border routers) establish BGP peering sessions with routers in neighboring ASes.
- Exchanging Prefixes: Through these sessions, they advertise the IP address prefixes (blocks of IP addresses) they are responsible for or can reach. For example, Google's AS (AS15169) might advertise reachability for prefixes like
142.250.0.0/16
. - Path Vector: BGP is a "path vector" protocol. When an AS advertises prefixes, it includes the path of ASNs the advertisement has traversed. This helps prevent routing loops and allows ASes to apply policies (e.g., "I prefer not to send traffic through AS X").
- Building Global Tables: Each BGP router aggregates the information received from its peers to build a massive BGP routing table, effectively mapping out how to reach different networks across the entire internet via specific neighboring ASes.
Figure 3: Simplified Autonomous Systems and BGP Peering.
Step 5: The Hop-by-Hop Relay
Combining these concepts, a packet's journey across the internet looks like this:
- Origin: Packet leaves your home router (Default Gateway) towards your ISP.
- ISP Network (AS): ISP routers use an IGP (like OSPF) to find the best path within the ISP's network to reach the appropriate border router.
- BGP Decision: The ISP's border router consults its BGP table. It determines which neighboring AS (e.g., a backbone provider, another ISP) offers the best path towards the destination IP address's network.
- Inter-AS Hop: The packet is forwarded to the border router of the neighboring AS.
- Repeat: This process repeats. The packet may traverse several different ASes. Routers within each AS use IGPs, while border routers use BGP to decide which AS to forward the packet to next. Each router along the path is a "hop".
- You can often see this using tools like
traceroute
(Linux/macOS) ortracert
(Windows).<FiTerminal className="inline mr-1"/> traceroute google.com
- You can often see this using tools like
- Destination AS: Eventually, the packet reaches the border router of the AS that manages the destination IP address (e.g., Google's AS15169).
- Final Internal Routing: Routers within the destination AS use their IGP to forward the packet to the specific subnet and, ultimately, the destination server.
Step 6: Reaching the Destination Server
Once the packet arrives at the final router connected to the destination server's local network segment, that router delivers the packet directly to the server based on its IP address.
The server's operating system receives the incoming packets, uses the sequence numbers in the TCP headers to reassemble the original data, and processes the request (e.g., prepares the Google homepage content).
The Return Trip
Communication is usually bidirectional. The destination server needs to send data back to you (e.g., the webpage content). It follows the exact same process in reverse:
- It breaks the response data into packets.
- Source IP is now the server's IP; Destination IP is your public IP address.
- Packets traverse routers and ASes, guided by BGP and IGPs, eventually reaching your ISP.
- Your ISP delivers the packets to your home router.
- Your router uses the NAT table records it created earlier to translate the destination public IP back to your device's private IP and forwards the packet to your device over the local network.
- Your device reassembles the packets to display the webpage.
Conclusion
Internet routing is a complex, distributed system built on layers of protocols and independent decisions made by millions of routers worldwide. From the initial DNS lookup and packetization to the hop-by-hop journey guided by routing tables built using IGPs and the global BGP protocol governing Autonomous Systems, it's a remarkable feat of engineering that allows data to traverse the globe, usually in fractions of a second. While largely invisible, this intricate dance of packets and routers underpins almost every interaction we have online.