Router vs Switch

Router operates at Layer 3 (Network) using IP addresses to connect DIFFERENT networks. Switch operates at Layer 2 (Data Link) using MAC addresses to connect devices within the SAME network.

Overview

Router and Switch are both network devices but operate at different OSI layers and serve different purposes.

Router — Layer 3 (Network Layer) - Operates at Layer 3 (Network Layer) - Uses IP addresses to make forwarding decisions - Connects DIFFERENT networks together - Routes packets between Network A and Network B - Example: home router connecting your LAN (192.168.1.0/24) to the internet - Maintains a routing table of known networks and next-hop paths

Switch — Layer 2 (Data Link Layer) - Operates at Layer 2 (Data Link Layer) - Uses MAC addresses to make forwarding decisions - Connects devices within the SAME network - Forwards Ethernet frames between devices on the same subnet - Example: office switch connecting desktops, printers, servers on 192.168.1.0/24 - Maintains a MAC address table (CAM table) mapping MAC → port

Key Difference Table

  • OSI Layer — Layer 3 (Network) — Layer 2 (Data Link)
  • Connects — Different Networks — Same Network
  • Address Used — IP Address — MAC Address
  • Function — Routing — Switching
  • Device — Packet — Frame

Quick Tip - Router = go OUTSIDE the network (between networks) - Switch = connect INSIDE the network (within a network)

Modern L3 Switches Modern Layer 3 switches combine both capabilities — switching (L2) within VLANs and routing (L3) between VLANs. They are common in enterprise data centers for inter-VLAN routing without a dedicated router.

Key concepts

Router
Layer 3 device using IP addresses to route packets between different networks. Maintains a routing table. Example: AWS VPC route table, home router, border router.
Switch
Layer 2 device using MAC addresses to forward frames within the same network. Maintains a MAC address table (CAM table). Example: office Ethernet switch, AWS VPC at the subnet level.
MAC Address Table (CAM Table)
Switch's internal table mapping MAC addresses to physical ports. Learned dynamically as frames arrive. Used to forward frames only to the correct port rather than flooding.
Routing Table
Router's table of known network prefixes and their next-hop addresses. Used to forward packets toward the destination network. Can be populated statically or via routing protocols (BGP, OSPF).
L3 Switch
A switch with built-in Layer 3 routing capability. Can route between VLANs without a separate router. Common in enterprise data center top-of-rack designs.

When to use it

  • Explaining why a home router connects you to the internet (different networks) but a switch just connects your local devices
  • Designing a network topology — routers at the perimeter/between subnets, switches within each subnet
  • Troubleshooting connectivity: Layer 2 (MAC/ARP) issues go to the switch, Layer 3 (IP/routing) issues go to the router
  • Justifying L3 switch use in a data center for inter-VLAN routing

Interview questions

  • What is the difference between a router and a switch?
  • When would you use a Layer 3 switch instead of a router?
  • How does a switch learn which MAC address is on which port?
  • In AWS, what plays the role of a router and what plays the role of a switch?

Sign up free to read the full topic

More Networking topics

Start free on Cariara · Coding problems · System design studio