What is the difference between a hub, a switch and a router?
Show the answer
Say this first
A hub is layer 1: it repeats every bit out every other port, so all ports share one collision domain and run half duplex. A switch is layer 2: it learns source MACs and forwards each frame only to the port where the destination lives; each port is its own collision domain, but all ports in a VLAN share one broadcast domain. A router is layer 3: it forwards packets between networks by IP address and does not forward broadcasts, so each interface is its own broadcast domain.
Go deeper
Comparison
| Hub | Switch | Router | |
|---|---|---|---|
| Layer | 1 | 2 | 3 |
| Decides on | Nothing | Destination MAC | Destination IP (longest prefix match) |
| Collision domains | One for all ports | One per port | One per interface |
| Broadcast domains | One | One per VLAN | One per interface |
| Duplex | Half only | Full on each port | Full on each interface |
| Unknown destination | Repeats everywhere | Floods within the VLAN | Drops (or uses default route) |
Details worth adding
- A switch floods three things inside the VLAN: broadcasts, unknown unicast and multicast without IGMP snooping.
- A router rewrites the layer 2 header and decrements TTL. A switch forwards the frame unchanged (apart from VLAN tagging).
- A layer 3 switch does both jobs in hardware. Routers usually win on WAN interfaces, deep buffers, large routing tables and features like NAT, VPN and full BGP tables.
They will ask next
Do hubs still matter?
Not in production. They matter as a concept: half duplex, one collision domain, and why CSMA/CD existed. A small "dumb" switch is still a switch.
How does a switch learn where a MAC lives?
From the source MAC of each frame it receives, recorded against the ingress port and VLAN. Entries age out after 300 seconds by default on Cisco switches if no frame from that MAC is seen.
Traps
- Saying a switch "breaks up broadcast domains". Only VLANs and routers do that.