How Routing Works

Run a Speed Test

Every packet you send crosses dozens of routers, each making an independent forwarding decision based on a routing table — this is how the internet routes at scale.

What a Router Does

A router is a device that forwards packets between networks. When a packet arrives on one of a router's interfaces, the router reads the destination IP address from the packet header and decides which interface to send it out on — and which next-hop address to hand it to. This forwarding decision is made independently at every router along the path, hop by hop, until the packet reaches its destination.

Routers operate at Layer 3 (the network layer) of the OSI model. They do not care about the application data inside the packet — they look only at the IP header. A router connecting your home network to your ISP, a core router in a tier-1 backbone carrying millions of packets per second, and a cloud provider's virtual router all make the same fundamental decision: look up the destination IP in the routing table and forward accordingly.

The key distinction between routing and switching: a switch connects devices within the same network using MAC addresses (Layer 2); a router connects different networks using IP addresses (Layer 3). Your home router does both — it switches traffic between devices on your local network and routes traffic between your local network and the internet.

Routing Tables: The Decision Lookup

Every router maintains a routing table — a database of destination prefixes and the next-hop address or outbound interface to use for each. When a packet arrives, the router performs a longest prefix match: it finds the most specific entry whose prefix matches the destination IP address and forwards the packet accordingly.

A simple routing table might look like this: 192.168.1.0/24 → directly connected on interface eth0; 10.0.0.0/8 → next hop 10.1.1.1 on eth1; 0.0.0.0/0 → next hop 203.0.113.1 (default route, matches everything). A packet destined for 192.168.1.50 matches the first entry (most specific, /24) and is delivered directly. A packet for 8.8.8.8 matches only the default route and is sent to the ISP gateway.

Longest prefix match is critical: if the table has both 10.0.0.0/8 and 10.1.0.0/16, a packet to 10.1.2.3 matches both — but the /16 is more specific and wins. This allows the internet's routing system to express both broad and precise routes simultaneously.

Static vs Dynamic Routing

AspectStatic RoutingDynamic Routing
ConfigurationManually entered by an administratorLearned automatically via routing protocols (BGP, OSPF, EIGRP)
ScalabilityPoor — impractical beyond a few routesExcellent — scales to hundreds of thousands of routes
Adapts to failuresNo — failed routes stay in the tableYes — protocols detect failures and reroute automatically
Use caseSmall networks, specific policy routes, default routes on edge devicesISP networks, enterprise WAN, internet backbone

BGP: The Protocol That Holds the Internet Together

BGP (Border Gateway Protocol), defined in RFC 4271, is the routing protocol used between autonomous systems — the independent networks that together form the internet. Every ISP, cloud provider, CDN, and large enterprise operates as an autonomous system (AS), identified by a unique Autonomous System Number (ASN). BGP is how these organizations exchange routing information with each other.

A BGP router (called a BGP speaker) announces the IP prefixes it can reach to its BGP peers. If AS 64500 (an ISP) has a customer network at 203.0.113.0/24, it announces that prefix to its upstream providers and peers. Those routers add the prefix to their tables, noting that traffic to 203.0.113.0/24 should be sent toward AS 64500. The announcement propagates across the internet, and eventually routers everywhere know how to reach that prefix.

BGP is a path-vector protocol — it carries not just the destination prefix but the full sequence of ASNs that traffic will traverse to reach it. This path information is used for loop prevention and policy decisions. BGP route selection involves many attributes: path length, local preference, origin, MED (Multi-Exit Discriminator), and more. Network operators configure policies to prefer certain paths over others, influence how their traffic enters and exits their network, and implement traffic engineering.

Autonomous Systems: The Building Blocks of Internet Routing

The internet is not a single network — it is tens of thousands of autonomous systems interconnected by BGP. Each AS is an independent administrative domain with its own routing policies. When you send a packet from your home network to a web server in another country, it typically crosses several autonomous systems: your ISP's AS, one or more transit provider ASes, and the destination network's AS.

Peering and transit are the two ways ASes connect. Transit means paying an upstream provider to carry traffic to and from the broader internet. Peering means two ASes agree to exchange traffic between their own customers for free (or at reduced cost), typically at an Internet Exchange Point (IXP) where many networks have co-located equipment. Major IXPs like DE-CIX in Frankfurt or AMS-IX in Amsterdam carry hundreds of terabits of traffic per second between hundreds of ASes.

How a Packet Travels from Your Device to a Server

When your browser connects to a web server, the packet journey proceeds hop by hop. Your device sends the packet to your default gateway (home router). Your router forwards it to your ISP's gateway. The ISP's routers forward it through their network, possibly across peering links to another AS. Transit routers in that AS forward it toward the destination AS. The destination AS's edge router delivers it to the web server. At every step, each router consults only its own routing table — no router knows the full path ahead, only the next hop.

This decentralized design is what makes the internet resilient. No single router needs a complete picture of every path. Failures are handled locally — when a link goes down, dynamic routing protocols redistribute routes around the failure within seconds to minutes. The internet routes around damage, as its designers intended.

Frequently Asked Questions

What is a routing table?

A routing table is a database in a router that maps destination IP prefixes to the next-hop address or outbound interface. When a packet arrives, the router finds the most specific matching prefix (longest prefix match) and forwards the packet to that next hop.

What is BGP?

BGP (Border Gateway Protocol) is the routing protocol that connects autonomous systems — the networks operated by ISPs, cloud providers, and large organizations. BGP routers exchange information about which IP prefixes each AS can reach, enabling internet-wide routing.

What is an autonomous system?

An autonomous system (AS) is a network under a single administrative authority with a unified routing policy, identified by an Autonomous System Number (ASN). ISPs, cloud providers, and large enterprises each operate as autonomous systems interconnected via BGP.

What is the difference between routing and switching?

Switching operates at Layer 2, forwarding frames based on MAC addresses within a single local network. Routing operates at Layer 3, forwarding packets based on IP addresses between different networks. A switch connects devices within a network; a router connects different networks.

What is a default route?

A default route (0.0.0.0/0 in IPv4) matches any destination not covered by a more specific entry. It is a catch-all that tells the router where to send traffic when it has no specific route for the destination. Home routers use a default route pointing to the ISP gateway for all internet-bound traffic.

What happens when a router doesn't know a destination?

If a router has no matching route and no default route, it drops the packet and sends an ICMP Destination Unreachable (Network Unreachable) message back to the source. If a default route exists, the packet is forwarded to the default next hop rather than dropped.

Related Guides

More From This Section