Hub vs Switch vs Router: OSI Layer, Addresses Used, Forwarding and Domains
All three connect devices and relay data, but they differ in which layer's information they use to forward it. A hub (repeater hub) is a layer 1 (physical layer) device that sends an incoming signal out of every port as is. A switch (L2 switch) is a layer 2 (data link layer) device that reads a frame's destination MAC address and forwards it only to the port where that destination is connected. A router is a layer 3 (network layer) device that relays packets between different networks based on the destination IP address and its routing table. Hubs and switches connect devices within one network; routers connect networks to each other.
| Aspect | Hub | Switch (L2 switch) | Router |
|---|---|---|---|
| Layer | Layer 1 (physical layer) | Layer 2 (data link layer) | Layer 3 (network layer) |
| Address used | None; it simply repeats the signal | MAC address | IP address |
| Data unit | Bits (electrical signals) | Frames | Packets |
| Forwarding method | Sends to every port except the one it arrived on | Learns which source MAC address is on which port in a MAC address table and sends only to the destination's port; unknown destinations and broadcasts go to every port except the incoming one (flooding) | Chooses the route in the routing table with the longest match to the destination IP address and sends to the next router or the destination, rewriting the frame's MAC addresses and decrementing the TTL by 1 |
| Collision domain | One for all ports; half duplex, so simultaneous sends collide | Separate for each port; no collisions when used in full duplex | Separate for each interface |
| Broadcast domain | One for all ports | One for all ports, or one per VLAN when divided by VLANs | Separate for each interface (network); broadcasts are not forwarded |
| Connecting different networks | No | No; it connects devices within one network (subnet) | Yes; many also provide NAT and packet filtering |
| Typical placement | Small, old networks; now almost entirely replaced by switches | Connecting PCs, servers, wireless LAN access points and so on to the same LAN | At the boundary between a LAN and the internet, and between segments (subnets) of an internal network |
Figures are typical orders of magnitude and vary by process generation and product.