All lessons are free · No login · No trackingStart learning

Network Stories 12 · Intermediate

Rue's Map: Routing Tables and Static Routes

How does Rue know the "next stop" for every letter?

Starring: Rue, PipAbout 10 min read

Recommended first: Story 11: “Subnetting”

1. The Story

Press "Next" to go through it step by step. In each step, one character steps up and explains what they are doing.

Prologue: a quick review

Step 1 of 10

Rue reads the IP to choose the next stop

I'm a Router. Every time I receive a Packet, I look at its IP destination and decide which stop to hand it to next. Mac wants to go to example.com, so I hand it over to the Internet side.

Animation text version (all steps)
  1. Prologue: a quick review
  2. Rue reads the IP to choose the next stop · Rue: I'm a Router. Every time I receive a Packet, I look at its IP destination and decide which stop to hand it to next. Mac wants to go to example.com, so I hand it over to the Internet side.
  3. Act 1: Rue's map
  4. Connecting to the studio Router · Rue: The upstairs studio Router and I are now joined by a network cable. This link uses 192.168.40.252/30: I'm .253 and it's .254. Inside the studio there are three networks: Office, CCTV and Servers.
  5. My map: the Routing Table · Rue: I have a map called a Routing Table. Networks connected directly to me are written in automatically when I start up. There's also a 0.0.0.0/0 line: "For everywhere else, hand it all to the ISP."
    • C 192.168.1.0/24 → directly connected (family zone)
    • C 192.168.20.0/24 → directly connected (guest zone)
    • C 192.168.40.252/30 → directly connected (to the studio)
    • C 203.0.113.0/24 → directly connected (outside, to the ISP)
    • S* 0.0.0.0/0 → 203.0.113.254 (ISP)
    • C = Connected
  6. To the studio? It's not on the map! · Pip: Mac wants to send a photo to the office PC 192.168.40.10. Rue checks his map: there's no 192.168.40.0 line! He has to use 0.0.0.0/0 and hand me to the Internet... I went to the wrong place, and in the end I was dropped!
    • A Router only knows the networks connected directly to it
    • The studio's networks are connected to the studio Router, so Rue has no idea they exist
  7. Act 2: Static Route
  8. Adding a line by hand · Rue: The network administrator adds a line to my map by hand: "192.168.40.0/24, hand it to 192.168.40.254." This is called a Static Route.
    • S = Static, typed in by hand
    • One /24 covers all three of the studio's /26 networks
  9. Made it this time! · Pip: Rue checks his map again: 192.168.40.10 matches 192.168.40.0/24, and the next stop is the studio Router. The studio Router checks its own map: the office is directly connected, so it delivers me to the office PC!
  10. The way back needs a route too · Rue: The office PC replies to Mac at 192.168.1.10. The studio Router's map has only its own networks, plus one Default Route: "For everywhere else, hand it to 192.168.40.253." So the reply can get back to me too.
    • Studio Router: S* 0.0.0.0/0 → 192.168.40.253
    • Common mistake: setting up the way there but forgetting the way back
  11. Several routes match? Pick the most precise · Rue: The destination 192.168.40.254 matches three Routes at once: /30, /24 and /0. I pick the /30, which has the longest prefix and is the most precise: it's directly connected to me! This is called Longest Prefix Match.
    • 192.168.40.252/30: prefix 30 ← longest, wins
    • 192.168.40.0/24: prefix 24
    • 0.0.0.0/0: prefix 0, the last resort
  12. Act 3: the map doesn't update itself
  13. The cable breaks · Pip: Oh no, the cable between the home and the studio has broken! Rue's Port loses its signal, and both the /30 and that Static Route disappear from the map. Rue has to use 0.0.0.0/0 and hand me to the ISP... and once again I can't reach the studio!
    • A Static Route won't find another way to the studio by itself
    • If the studio Router crashes but the Port light stays on, the Static Route keeps pointing to .254, and Pip falls into a black hole
    • Someone has to wait for the network administrator to spot the problem and fix it by hand
  14. Summary: Rue's map · Rue: A Routing Table says "which network, and which stop to hand it to". Static Routes are simple and clear, but they stop working well as soon as the network changes. If only we Routers could swap information and find new routes automatically... See you in the next story!
    • Where Routes come from: directly connected, Static Routes, Dynamic Routing
    • 0.0.0.0/0 = Default Route
    • When several match, pick the one with the longest prefix

2. Where Is the Problem

Rue is a Router. Every time he receives a Packet, he looks at the IP destination and decides which stop to hand it to next.

When Mac opens example.com (192.0.2.80), Rue hands Pip to the ISP (Internet Service Provider), and everything goes smoothly. An address starting with 192 is not always a Private IP. Only addresses starting with 192.168 are.

But when Mac sends a photo to the office PC 192.168.40.10 in the studio, Pip can't get there:

  • The studio's three networks are connected to the studio Router, not to Rue.
  • Rue only knows the networks connected directly to him. He has no idea that the office's 192.168.40.10 is upstairs.
  • With no better route, Rue has no choice but to hand Pip to the ISP. Routers on the Internet don't forward Packets addressed to a Private IP, so Pip ends up being dropped.

3. How the Network Solves It

Rue carries a map. Each line on it says: "To reach this network, hand it to this stop." This map is called a Routing Table. It's the table a Router uses to decide where to send each Packet.

The routes on the map come from three sources:

  1. Networks connected directly to Rue are written in automatically when he starts up.
  2. A line added by hand by the network administrator. This is called a Static Route.
  3. Routes that Routers swap with each other automatically. This is called Dynamic Routing, and it's coming up in the next story.

4. A Closer Look

The link between the home and the studio

Rue and the studio Router are joined by one network cable. That cable is a network of its own: 192.168.40.252/30.

A /30 slice has only 4 addresses, which is just right for a link with only two Routers. It's a small piece cut out of the fourth slice, 192.168.40.192/26, that was kept spare in the previous story:

Address Use
192.168.40.252 Network Address
192.168.40.253 Rue, at home
192.168.40.254 Studio Router
192.168.40.255 Broadcast Address

Rue's Routing Table

After adding the Static Route, Rue's map looks roughly like this:

Code  Destination network   Next stop / exit
C     192.168.1.0/24       Directly connected (family zone)
C     192.168.20.0/24      Directly connected (guest zone)
C     192.168.40.252/30    Directly connected (to the studio)
C     203.0.113.0/24       Directly connected (outside, to the ISP)
S     192.168.40.0/24      Via 192.168.40.254
S*    0.0.0.0/0            Via 203.0.113.254 (ISP)
  • C = Connected Route: a network plugged into one of Rue's own Ports. It appears automatically at start-up.
  • S = Static: typed in by hand by the network administrator.
  • Next stop: also called the Next Hop. It's the IP Address of the next Router the Packet should be handed to, and it must be an address Rue can reach directly.
  • * means this is the Default Route. Its next stop, 203.0.113.254, is inside the directly connected 203.0.113.0/24, so Rue can find it.

One 192.168.40.0/24 line already covers all three of the studio's /26 networks, so there's no need to write them one by one.

Default Route: 0.0.0.0/0

The prefix length of 0.0.0.0/0 is 0, which means "compare not a single bit", so every address matches. It means: "For everywhere else, take this route."

A home Router usually has only this one Default Route, pointing to the ISP Router 203.0.113.254.

Several routes match? Longest Prefix Match

One destination address can match several Routes at the same time. Rue picks the one with the longest prefix, because it's the most precise. This is called Longest Prefix Match.

Take the destination 192.168.40.254 as an example:

Route Prefix length Does it match?
192.168.40.252/30 30 Match ← longest, wins
192.168.40.0/24 24 Match
0.0.0.0/0 0 Match (every address matches)

So 192.168.40.254 is sent out directly. 192.168.40.10 only matches /24 and /0, so /24 is chosen and it goes to the studio Router. 192.0.2.80 only matches /0, so it goes to the ISP.

Note: the order of the lines on the map doesn't affect the result. The prefix length is what matters.

The way back needs a route too

When the office PC replies to Mac at 192.168.1.10, the studio Router decides the route. Its map has only its own networks, plus one Default Route:

S*    0.0.0.0/0            Via 192.168.40.253 (Rue, at home)

So the reply can get back to Rue, who then delivers it to Mac. Setting up the way there but forgetting the way back is the most common mistake when configuring Static Routes.

The weakness of Static Routes

A Static Route won't find another way by itself. In the story, the cable between the home and the studio breaks:

  1. Rue's Port loses its signal, and 192.168.40.252/30 disappears from the map.
  2. The next stop 192.168.40.254 can no longer be reached, so that Static Route stops working too.
  3. For 192.168.40.10, only 0.0.0.0/0 still matches. Rue hands Pip to the ISP, and he still can't reach the studio.

Another case is even trickier: if the studio Router crashes but Rue's Port light is still on, the Static Route keeps pointing to 192.168.40.254, and Pip falls into a "black hole".

Either way, someone has to wait for the network administrator to spot the problem and fix it by hand.

5. Try It Yourself

Task: look at your computer's Routing Table

  1. On a Windows computer, open "Command Prompt" and type route print. On a Mac or Linux, open "Terminal" and type netstat -rn.
  2. Look for the 0.0.0.0 line (some systems show it as default): its next stop is your Default Gateway.
  3. So it's not just Routers. Your computer has a little map too!

Mini game

Which Route will Rue pick?

How will Rue handle each of these destinations?

  1. 1192.0.2.80

  2. 2192.168.40.10

  3. 3192.168.1.11

  4. 4192.168.40.254

  5. 5192.168.20.10

  6. 6198.51.100.1

6. Where the Analogy Breaks

  • The map doesn't show the full route. Rue only knows the "next stop". He doesn't know which Routers Pip will pass through after that. Every stop checks its own map.
  • Real maps can be very long. A home Router has only a few lines, but large Routers on the Internet have around a million Routes and use special chips to look them up quickly.
  • Rue doesn't really "flip through" his map. The animation draws the lookup as flipping through a book. In reality, a Router uses special data structures to find the line with the longest prefix in a tiny fraction of a second.
  • When prefixes are equally long, there are other rules. If two Routes have exactly the same network and prefix but come from different sources (for example, one Static and one Dynamic), the Router picks one by how "trustworthy" each source is. We won't go into that here.
  • The way back doesn't always follow the way there. In this story there's only one route, so both directions are the same. In large networks, the way there and the way back can take different routes.

7. Quiz

Question 1 of 3What does the Route 0.0.0.0/0 mean?
Question 2 of 3Rue's Routing Table has both 192.168.40.0/24 and 192.168.40.252/30. For the destination 192.168.40.254, which one will he pick?
Question 3 of 3Which of these is a downside of Static Routes?

8. Key Notes

  • Each line of a Routing Table says "which network, and which stop to hand it to". A Router only knows the next stop, not the whole route.
  • Routes come from three sources: Connected Routes, Static Routes (typed in by hand) and Dynamic Routing (swapped automatically).
  • 0.0.0.0/0 is the Default Route. Every address matches it, and it's used only when no more precise Route can be found.
  • When several Routes match, the one with the longest prefix is chosen. This is called Longest Prefix Match.
  • Static Routes are simple and clear, but they don't update automatically when the network changes. And there must be a route both there and back.

Further reading

With only two Routers, writing a few Static Routes by hand is still manageable. But what about ten Routers, or a hundred, with cables breaking now and then? In the next story, Professor Arpa explains how Routers swap information automatically: Dynamic Routing and OSPF (Open Shortest Path First).