Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →

Hub vs Switch vs Router: Network Devices Explained

Understand the difference between hubs, switches, routers and other network devices, which OSI layer each works at, and how switches learn MAC addresses.

JioCoderUpdated Oct 11, 20262 min readNetworking
Hub vs Switch vs Router: Network Devices Explained

Hubs, switches and routers all move data, but they make very different decisions about where that data goes. The easiest way to understand them is by the OSI layer they operate at.

Devices by OSI layer#

Network devices by OSI layer: hub at layer 1, switch at layer 2, router at layer 3, firewall and load balancer at layer 7

Hub (Layer 1)#

A hub is a simple repeater with many ports. Whatever signal arrives on one port is copied to every other port. It has no idea what a MAC or IP address is.

  • All devices share one collision domain – only one can transmit at a time.
  • Every device sees every frame, which is inefficient and insecure.
  • Hubs are essentially obsolete; you'll mostly meet them in textbooks and interviews.

Switch (Layer 2)#

A switch forwards Ethernet frames based on MAC addresses. It learns which device is on which port and sends frames only where they need to go.

How a switch learns#

  1. A frame arrives on port 3 from MAC AA:AA. The switch records "AA:AA is on port 3" in its MAC address table (CAM table).
  2. If the destination MAC is already in the table, the frame goes out only that port.
  3. If the destination is unknown (or it's a broadcast), the switch floods it to all ports except the source. The reply teaches it the missing entry.

Each switch port is its own collision domain, and full-duplex links remove collisions entirely. All ports are still in one broadcast domain unless you use VLANs.

Note

Layer 3 switches can also route between VLANs at hardware speed. In data centers, the line between "switch" and "router" is often blurry.

Router (Layer 3)#

A router connects different networks and forwards packets based on IP addresses. It looks up the destination in its routing table and picks the best next hop.

  • Each router interface is a separate broadcast domain – routers don't forward broadcasts.
  • Home routers usually combine a router, switch, Wi-Fi access point, DHCP server, NAT and firewall in one box.
  • Routers decrement the IP TTL at each hop, which is how traceroute discovers the path.

Comparison#

Hub vs switch vs router comparison: broadcasting, MAC learning, IP routing and NAT
FeatureHubSwitchRouter
OSI layer123
Forwards byNothing – repeatsMAC addressIP address
Collision domainsOne sharedOne per portOne per port
Broadcast domainsOneOne (per VLAN)One per interface
Typical useLegacyConnect devices in a LANConnect LANs and the internet

Other devices you'll meet#

  • Access point – bridges Wi-Fi clients onto a wired LAN.
  • Modem / ONT – converts between your network and the ISP's cable, DSL or fiber line.
  • Firewall – filters traffic by rules, from simple port blocks to deep application inspection.
  • Load balancer – spreads requests across multiple servers.
  • Bridge – an older two-port Layer 2 device; a switch is essentially a multi-port bridge.
Bash
# See your machine's routing table
ip route            # Linux
route print         # Windows
netstat -rn         # macOS

# See IP-to-MAC mappings learned via ARP
ip neigh            # Linux
arp -a              # Windows / macOS

Key takeaways#

  • Hubs repeat bits to every port (Layer 1).
  • Switches forward frames by MAC address and learn a MAC table (Layer 2).
  • Routers forward packets by IP address between networks (Layer 3).
  • Switches split collision domains; routers split broadcast domains.