Overview
Network devices move data between computers at different layers of the network. A hub (layer 1) repeats every signal to every port. A switch (layer 2) learns which device is on which port using MAC addresses and forwards frames only where needed. A router (layer 3) connects different networks and forwards packets by IP address, choosing paths using routing tables.
A home "router" usually combines several devices in one box - a modem (converts the provider's signal to Ethernet), a router with NAT, a switch, a Wi-Fi access point, a DHCP server, and a firewall. In data centers these roles are separate, and load balancers, firewalls, and gateways sit on top of the same foundations.
A hub is someone shouting every letter to the whole floor. A switch is a mail clerk who knows which desk each person sits at. A router is the post office that sends letters to other buildings and cities by address.
When to use it
- Understanding how a request physically reaches a server.
- Explaining latency, broadcast domains, and network segmentation.
- Designing VPCs, subnets, and on-premises networks.
- Debugging connectivity problems.
Where it shows up in interviews
Recognize it when: "What happens when you type a URL?" at the network level.
- Explain how a packet reaches a web server
- Design network segmentation for a company
Recognize it when: subnets, gateways, and routing in a VPC.
- Design a secure three-tier VPC
- Connect on-premises to the cloud
Where it is used in real software
ISP gateways combine modem, router, NAT, DHCP, Wi-Fi access point, and firewall in one device.
Leaf-spine architectures use top-of-rack switches connected to spine switches for predictable, low-latency east-west traffic.
AWS route tables, internet gateways, and NAT gateways are software-defined versions of routers and NAT devices.
Key terms
- MAC address
- Hardware address used by switches within a local network (layer 2).
- IP address
- Logical address used by routers across networks (layer 3).
- Routing table
- Rules mapping destination networks to next hops.
- NAT
- Rewrites private addresses to a public one so many devices share one IP.
- Broadcast domain
- Set of devices that receive each other's broadcasts; routers separate them.
How it works, step by step
- 1Device sends a frame
The laptop wraps an IP packet in an Ethernet or Wi-Fi frame addressed to the gateway's MAC address.
- 2Switch forwards locally
The switch looks up the destination MAC in its table and sends the frame out one port.
- 3Router forwards between networks
The router reads the destination IP, consults its routing table, applies NAT, and sends it toward the ISP.
- 4Internet routers hop the packet
Each router forwards to the next hop until the destination network is reached.
- 5Destination network delivers
The server's router and switch deliver the packet to the server's network card.
STEP 1The laptop sends a frame to the gateway's MAC address. The switch forwards it only to the router's port.
Device comparison
What each device looks at and does
| Device | OSI layer | Uses | Behavior |
|---|---|---|---|
| Hub | 1 (physical) | Nothing (signals only) | Repeats to all ports; collisions and wasted bandwidth |
| Switch | 2 (data link) | MAC addresses | Learns ports; forwards to the right device |
| Router | 3 (network) | IP addresses | Connects networks; chooses paths; often NAT |
| Modem | 1-2 | Provider signal | Converts cable/DSL/fiber to Ethernet |
| Access point | 2 | MAC addresses | Bridges Wi-Fi clients to the wired network |
NOWDevice: Hub | OSI layer: 1 (physical) | Uses: Nothing (signals only) | Behavior: Repeats to all ports; collisions and wasted bandwidth
Switches keep local traffic efficient; routers connect networks and define boundaries.
Implementation
# Your interfaces, IP, and MAC addressip addr # Linux (macOS: ifconfig) # Default gateway (your router)ip route | grep default # Linux (macOS: netstat -rn | grep default) # MAC addresses the machine has learned on the local network (ARP table)arp -a # Every router hop between you and a servertraceroute example.com # Is the path healthy? Packet loss and latency per hopmtr -rwzc 20 example.comComplexity and performance
In hardware at line rate.
Specialized hardware (TCAM) or tries.
Trade-offs
A flat network is simple but lets broadcasts and attacks spread; routing between subnets adds isolation and control at the cost of configuration.
All-in-one home devices are convenient; dedicated devices in data centers scale better and fail independently.
Variants and related techniques
Switches that also route between VLANs at hardware speed.
Cloud providers implement routers, switches, and firewalls in software controlled by APIs.
Common mistakes
- Calling every box a router.
Fix: Distinguish modem, router, switch, and access point roles when explaining network paths.
- Assuming a private IP is reachable from the internet.
Fix: Private addresses are translated by NAT; inbound access needs port forwarding, a load balancer, or a public IP.
Interview questions
What is the difference between a switch and a router?
A switch forwards frames within one local network using MAC addresses. A router connects different networks and forwards packets using IP addresses and routing tables, often also performing NAT.
How does a router choose where to send a packet?
It finds all routing table entries whose network contains the destination IP and picks the most specific one (longest prefix match), falling back to the default route 0.0.0.0/0.
Practice problems
| Problem | Difficulty | What it trains |
|---|---|---|
| Trace a packet from laptop to server | Easy | Device roles. |
| Design subnets and routes for a three-tier app | Medium | Segmentation. |