Packet.School
HomeLevelsSandboxFreeAbout
XP0
L4 · Network Devices
Level 4
5 lessons
  • 01Hub vs Switch
  • 02Router
  • 03Build Network Topology
  • 04Firewall
  • 05Level 4 Quiz
Levels/L4 · Network Devices/Lesson 02
Lesson · 02

Router

A router works at OSI Layer 3 (Network) and connects different networks together. A switch answers "which device inside this building?"; a router answers "which building?"

Duration
3min
Level
L4
Type
Lesson
Progress
2/ 5

01What does a router do?

  1. Routing — picks the best path to the destination
  2. Network separation — connects different LANs, stops broadcasts
  3. NAT — translates private IPs to public ones
  4. DHCP — hands out IPs (on home routers)
  5. Firewall — basic traffic filtering (on home routers)

A home router is really five devices in one box: router + switch + access point + DHCP server + firewall.

02Routing

The routing table

code
Destination       Interface   Next hop
192.168.1.0/24    eth0        Directly connected
10.0.0.0/8        eth1        192.168.1.254
0.0.0.0/0         eth2        ISP Gateway

The last line is the default route: any packet matching no other rule leaves "toward the internet" through this door.

The routing process

  1. A packet arrives → destination IP is read
  2. The routing table is consulted
  3. The most specific match wins (longest prefix match)
  4. The packet departs through that interface

03Home vs enterprise router

FeatureHome routerEnterprise router
Ports4–824+
Speed1 Gbps10–100 Gbps
FeaturesNAT, DHCP, Wi-Fi all-in-oneRouting only
ManagementWeb UICLI / SSH

04Static vs dynamic routing

Static routing

Written by hand, never changes. For small, predictable networks:

code
ip route 10.0.0.0/8 192.168.1.254

Dynamic routing

Routers learn routes from each other and find alternatives when a link dies:

  • OSPF — medium/large enterprise networks
  • BGP — the internet's backbone; route exchange between ISPs
  • RIP — first generation, now mostly in textbooks

05What changes as a packet crosses a router?

code
[Ethernet Header][IP Header][Data]
      ↓              ↓
   Changes       Unchanged

Source MAC: becomes the router's MAC
Dest MAC:   becomes the next hop's MAC
Source IP:  stays original
Dest IP:    stays original

The rule you learned earlier is at work here: MAC addresses are renewed hop by hop, IPs stay fixed end to end.

06Switch vs router

FeatureSwitchRouter
LayerLayer 2Layer 3
Looks atMACIP
BroadcastsForwardsStops
Used forInside a LANBetween LANs

07Real-world example

code
Internet
    |
 [Router] ← NAT, firewall
    |
 [Switch]
  /    \
PC1    PC2
  1. PC1 wants to reach google.com
  2. The packet travels through the switch to the router
  3. The router applies NAT (private IP → public IP) and sends it out
  4. When the reply returns, the NAT table points back to PC1
Sandbox · AnimationPacket JourneyWatch the packet swap MACs at the router while keeping its IPs — step by step in the animation.Open tool

08Summary

  • Router = connects different networks, works at Layer 3
  • Picks paths with a routing table + longest prefix match
  • Stops broadcasts (every port is its own broadcast domain)
  • A home router is five devices sharing one box
Previous
Hub vs Switch
Next
Build Network Topology
On this page
  • What does a router do?
  • Routing
  • Home vs enterprise router
  • Static vs dynamic routing
  • What changes as a packet crosses a router?
  • Switch vs router
  • Real-world example
  • Summary
Packet.School

An open, interactive curriculum for computer networking.

v3.0 · MIT22 lessons live

Learn

  • Lessons
  • Sandbox
  • Levels
  • Free
  • About

Simulations

  • Packet Journey
  • DNS Lookup
  • DHCP Simulator
  • Subnet Calc
  • Network Builder
  • Terminal

Project

  • About
  • Changelog
  • GitHub
  • Contributing
  • Style guide

Newsletter

One short email when a new level ships. No tracking pixels.

© 2026 Packet.School — MIT licensedSupport with a coffeebuilt in the open