← Lessons

quiz vs the machine

Silver1040

Networking

How the Internet Routes Packets

How a packet hops router to router toward its destination address.

4 min read · intro · beat Silver to climb

Hop by hop

The internet does not hold an end to end circuit. Instead each packet carries a destination IP address, and every router along the way makes an independent forwarding decision. No single device knows the whole path.

The routing table

A router keeps a routing table mapping address prefixes to next hops:

  • It compares the destination against each prefix and picks the longest prefix match, the most specific entry.
  • That entry names an outgoing interface and the next router to forward to.
  • If nothing matches, the packet follows the default route toward the wider internet.

Routers learn these prefixes from protocols like BGP between networks and OSPF inside one network. Each hop decrements the time to live field, and a packet that reaches zero is dropped so loops cannot run forever.

Why this scales

Because forwarding is local and stateless, routers do not track every connection. They only need prefixes, so a handful of table entries can reach billions of addresses. This is why the internet keeps working even when links fail and traffic reroutes around them.

Key idea

Packets are forwarded one hop at a time by longest prefix match, with no router holding the full end to end path.

Check yourself

Answer to earn rating on the learn ladder.

1. How does a router choose where to forward a packet?

2. What stops a misrouted packet from looping forever?