← All posts
7 min read

Routers and Routing: How Packets Find the Next Hop

#technology#computer-science#routing#networking
📑 On this page

A packet traveling from your phone to a server on another continent may cross many routers. No single home router needs a detailed map of every cable and machine along the complete path.

Each router solves a smaller problem:

Given the packet's destination address, which next hop or outgoing interface moves it closer to the correct network?

Routing is a chain of local forwarding decisions built from shared reachability information.

What a router connects

A router has interfaces connected to different IP networks.

A home router might connect:

  • Home LAN
  • Internet provider access network
  • Guest network
  • VPN tunnel

An internet backbone router can connect several high-capacity provider links.

When a packet arrives, the router determines whether it should:

  • Deliver to a directly connected network
  • Forward to another router
  • Drop the packet
  • Send an error response

Routers separate broadcast domains and enforce policy between networks.

The routing table

A routing table contains entries such as:

destination prefix     next hop          interface
192.168.1.0/24         directly connected LAN
203.0.113.0/24         198.51.100.2      uplink A
0.0.0.0/0              198.51.100.1      default

Each entry describes a range of destination addresses.

Routes can come from:

  • Directly connected interfaces
  • Manual configuration
  • Dynamic routing protocols
  • VPN software
  • Provider advertisements

The forwarding plane uses this information for packets. The control plane learns and maintains it.

Longest-prefix matching

Several routes can match one destination.

Suppose the table contains:

10.0.0.0/8
10.20.0.0/16
10.20.30.0/24

For destination 10.20.30.55, all three match. The router chooses /24 because it has the longest, most specific prefix.

This allows broad summary routes plus exceptions.

A default route:

0.0.0.0/0

matches every IPv4 address but loses whenever a more specific route exists.

Next hop

A route often identifies a next-hop router, not the final destination.

The current router uses the local link to send a frame to that next hop. The next router repeats the IP lookup.

This resembles postal sorting:

  • A local office sends international mail to a regional center.
  • The regional center sends it toward the destination country.
  • Later centers make increasingly local choices.

No sorting center needs every delivery detail from the beginning.

A concrete forwarding example

A laptop sends a packet to 203.0.113.50.

  1. The laptop sees that the destination is outside its local prefix.
  2. It sends the frame to its default gateway.
  3. The home router checks its routing table and uses the provider uplink.
  4. The provider edge router selects a route toward the destination network.
  5. Transit or peering routers repeat the process.
  6. A destination-network router reaches the server's subnet.
  7. The final local link delivers the packet.

At each router, the link-layer frame changes. The packet's destination IP remains the server unless translation or tunneling modifies the path.

Static routing

A static route is configured manually.

It works well for:

  • Simple networks
  • Predictable paths
  • Default routes
  • Small private connections

Advantages:

  • Explicit behavior
  • Low protocol overhead
  • No unexpected learned routes

Disadvantages:

  • Manual maintenance
  • Poor adaptation to failures
  • Difficult scaling

If a link fails, a static route remains unless monitoring or automation removes it.

Dynamic routing

Dynamic routing protocols let routers exchange reachability.

Within an organization or provider, protocols such as OSPF or IS-IS distribute internal topology information.

Between autonomous systems, BGP exchanges network prefixes and policy attributes.

Routers calculate preferred paths based on:

  • Metrics
  • Policy
  • Administrative preference
  • Path attributes
  • Link state

Dynamic does not mean random. Operators configure policy, and protocols react within those rules.

Routing metrics are not only distance

A preferred route may depend on:

  • Hop count
  • Link cost
  • Bandwidth
  • Delay
  • Reliability
  • Business policy

BGP frequently chooses paths based on policy before simple physical distance.

A provider may route traffic through a commercially preferred neighbor even if another route appears geographically shorter.

The internet path is shaped by engineering and economics.

Route aggregation

Routers cannot hold one separate global route for every individual device.

Address allocation is hierarchical, allowing networks to advertise summarized prefixes.

A provider can announce one larger prefix covering many customer networks. More-specific announcements can express exceptions.

Aggregation reduces routing-table size and update traffic.

Poorly planned address allocation makes summarization harder.

Routing loops

A routing loop occurs when routers forward a packet in a cycle.

Example:

Router A sends to B
Router B sends to C
Router C sends back to A

The packet's TTL or Hop Limit decreases at each router. When it reaches zero, the packet is discarded.

Routing protocols use sequence information, topology calculations, and loop-prevention rules, but temporary loops can occur during changes.

Convergence

After a link or route changes, routers need time to learn and calculate new paths. This is convergence.

During convergence:

  • Packets may follow old routes.
  • Some destinations may be temporarily unreachable.
  • Traffic can shift and congest another link.

Fast convergence improves availability but creates processing and stability trade-offs. Reacting too aggressively to a flapping link can spread continual changes.

Equal-cost paths

A router may have several equally preferred paths.

Equal-cost multipath routing can distribute flows across them, improving capacity and resilience.

Packets in one flow are often kept on one path to avoid reordering. Hashing fields such as source, destination, and ports chooses a path.

One large flow may therefore use only one member, while many flows spread well.

Routers and firewalls

Routing answers where traffic can go. Firewall policy answers whether it is allowed.

A device can perform both functions, but the decisions are conceptually separate.

No route means the packet lacks a forwarding path. A firewall drop means a path exists but policy rejects the traffic.

Troubleshooting should check:

  1. Interface state
  2. Addressing
  3. Route selection
  4. Neighbor reachability
  5. Firewall policy
  6. Return route

Common misunderstandings

"A router knows the packet's complete path"

It usually knows the next hop for the destination prefix, not every future router.

"Fewest hops always means fastest"

Links differ in capacity, delay, congestion, and policy.

"The outgoing and return paths must be identical"

Internet routing is often asymmetric. Each direction is chosen independently.

"A default route overrides specific routes"

It is the least-specific match and is used only when no more-specific route wins.

Knowledge check

1. Which route wins for 10.20.30.5: /8, /16, or /24?

The /24 route wins because it is the longest, most-specific matching prefix.

2. What is a next hop?

It is the next router or directly connected destination to which the current router forwards a packet.

3. Why do dynamic routing protocols exist?

They exchange reachability and adapt routes when topology or policy changes.

4. What limits packets caught in a loop?

IPv4 TTL or IPv6 Hop Limit decreases at each router until the packet is discarded.

The one idea to remember

Routing is hop-by-hop prefix matching.

Each router chooses the most specific available route and forwards the packet to a next hop, while routing protocols and operator policy maintain the information behind those choices.

Next, we will examine the access equipment and provider network that carry a home or office beyond its local router.