INTERNET FUNDAMENTALSAI-REVIEWED

How do routers choose where packets go?

Useful first: IP addresses · optional, not a requirement

Choose your depth

Stay with the essentials, or look closer.

Simple explanation
2 min read · estimate

YOUR GOALExplain what a router does without confusing it with name lookup or address translation.

Finding the next handoff

One step between networks

A router connects networks and forwards packets between them. Think of a parcel sorting desk: it chooses the next handoff, rather than carrying the parcel all the way to its destination.

Here we focus on ordinary destination-based IPv4 unicast: traffic addressed to one destination. The router consults forwarding information for the destination IP address.

[1] [2]

An exit for your laptop

On a simple office network, a laptop can send directly to a nearby printer on its own subnet. To reach another network, it can send through a router. A configured default gateway supplies a fallback next hop when no more specific route applies.

The gateway is a next step. Its presence does not prove that every later step will work.

[3] [4]

Three jobs, sometimes one box

DNS can resolve a hostname to an IP address. Routing chooses where a packet goes next. NAT, network address translation, changes addresses; a common form also translates transport ports.

A home networking box may perform several of these jobs. That does not make them the same operation, or make NAT necessary for every routed packet.

[1] [6] [7]
THE IDEA TO KEEP

A router makes a forwarding decision for the next handoff; DNS and NAT solve different problems.

ONE THING TO WATCH OUT FOR

Routing turns a website name into an IP address.

DNS handles name lookups. Destination-based IP forwarding uses the packet's destination address to choose a next hop.

A QUICK CHECK, NOT A TEST
After a packet has a destination IP address, what does a router do in this explanation?
Show the explanation

Choose a next hop using forwarding information for that address. Routing selects the next handoff toward an IP destination. It is not a DNS lookup and does not automatically encrypt traffic.

Progress is saved only in this browser.

KEEP EXPLORINGIP addresses
Was this explanation clear?
Report a mistake by email
Basic explanation
2 min read · estimate

YOUR GOALDistinguish a directly connected destination, a specific route through a gateway and a default route.

Reading a small route table

Nearby or beyond the subnet?

Suppose a laptop has one interface, address 192.168.10.20/24 and mask 255.255.255.0. With no special route overriding this example, 192.168.10.50 is on its local subnet; 10.20.30.40 is not.

The mask identifies which address bits describe the subnet. Comparing the first three dotted numbers works here because this example uses /24; it is not a rule for every IPv4 network.

[3] [5]

A route and its next hop

Consider this simplified forwarding table for that laptop. Both gateway addresses are reachable on its office link:

Destination       Interface  Next hop
192.168.10.0/24   office     directly connected
10.20.0.0/16      office     192.168.10.1
0.0.0.0/0        office     192.168.10.254

The printer at 192.168.10.50 is reached directly. For 10.20.30.40, the laptop selects the /16 entry and hands the packet to 192.168.10.1. That gateway makes its own forwarding decision next.

[3] [4] [5]

Default means fallback

The prefix 0.0.0.0/0 matches every IPv4 destination, but loses to any more specific matching route. In this table, 10.21.1.5 therefore uses the default entry through 192.168.10.254.

The default route is the table entry. Its gateway is the next-hop router named by that entry. A configured route is not a test of internet reachability.

[3] [5]
THE IDEA TO KEEP

Read the destination prefix and next hop together; use the default only when no more specific route matches.

ONE THING TO WATCH OUT FOR

Every outgoing packet must go through the default gateway.

Directly connected destinations and more specific matching routes can take precedence over the default route.

A QUICK CHECK, NOT A TEST
Using the illustrated laptop table, where is a packet for 10.20.30.40 sent next?
Show the explanation

To 192.168.10.1 because 10.20.0.0/16 matches more specifically. 10.20.30.40 matches the /16 route, which is more specific than /0. It is outside the laptop's directly connected 192.168.10.0/24 subnet.

Progress is saved only in this browser.

KEEP EXPLORINGIP addresses
Was this explanation clear?
Report a mistake by email
Advanced explanation
3 min read · estimate

YOUR GOALChoose among overlapping installed IPv4 routes and separate forwarding from route learning and delivery guarantees.

Applying longest-prefix matching

Match first, then compare lengths

In one ordinary destination-based forwarding table, first retain routes whose prefixes match the destination. Then prefer the matching prefix with the most significant bits. Assume these routes are installed and gateways A through D are reachable:

10.20.0.0/16      via A
10.20.30.0/24     via B
10.20.30.128/25   via C
0.0.0.0/0        via D

10.20.30.140 selects C; 10.20.30.25 selects B; 10.20.40.5 selects A; 10.21.1.5 selects D. The /25 covers final-octet values 128 through 255 within this /24, so it does not match 10.20.30.25.

[4] [5]

How entries get there is another question

Forwarding uses the available table entries. Administrators can configure static routes; dynamic routing protocols exchange information used to update routes as networks change.

A longer matching prefix is a more specific destination range, not a measured promise of lower latency. Comparing equally specific alternatives, routing policies and multiple-path selection requires additional rules beyond this example.

[2] [4]

An entry is not completed delivery

Remove the default route from the example and 10.21.1.5 matches none of the remaining entries. With no usable route, the router cannot forward it toward that destination.

Even a selected next hop is not an end-to-end guarantee: another router farther along can lack a route, or a link can fail. Diagnose the destination, matching entry and next hop separately before assuming that name resolution or NAT is the cause.

[2] [4]
THE IDEA TO KEEP

Choose the most specific matching installed route, then remember that later hops must also be able to forward the packet.

ONE THING TO WATCH OUT FOR

The route with the largest slash number always wins, even if its prefix does not match.

Only matching prefixes compete. A /25 for a different address range cannot override a matching /24.

A QUICK CHECK, NOT A TEST
For 10.20.30.140 in the four-route example, which entry wins and why?
Show the explanation

The /25 route via C, because it matches the greatest number of prefix bits. The address lies in 10.20.30.128/25 and also matches /24, /16 and /0. The /25 is the most specific match; prefix length does not measure speed.

Progress is saved only in this browser.

KEEP EXPLORINGIP addresses
Was this explanation clear?
Report a mistake by email
GO STRAIGHT TO THE SOURCE

Keep asking. Check the details.

Source-checked using AI (OpenAI Codex) on . The checks covered sources, examples, and quizzes for this article version.

No human review is claimed. AI review can miss errors; check the original sources below.

  1. Cloudflare — What is a router?
  2. Cloudflare — What is routing?
  3. RFC 1122 — Host requirements: local and remote destinations
  4. RFC 1812 — IPv4 router forwarding and next-hop selection
  5. RFC 4632 — CIDR prefixes and longest-match forwarding
  6. RFC 3022 — Network address translation
  7. Cloudflare — What is DNS?
How explanations are prepared