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.

AspectHubSwitch (L2 switch)Router
LayerLayer 1 (physical layer)Layer 2 (data link layer)Layer 3 (network layer)
Address usedNone; it simply repeats the signalMAC addressIP address
Data unitBits (electrical signals)FramesPackets
Forwarding methodSends to every port except the one it arrived onLearns 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 domainOne for all ports; half duplex, so simultaneous sends collideSeparate for each port; no collisions when used in full duplexSeparate for each interface
Broadcast domainOne for all portsOne for all ports, or one per VLAN when divided by VLANsSeparate for each interface (network); broadcasts are not forwarded
Connecting different networksNoNo; it connects devices within one network (subnet)Yes; many also provide NAT and packet filtering
Typical placementSmall, old networks; now almost entirely replaced by switchesConnecting PCs, servers, wireless LAN access points and so on to the same LANAt 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.

When to use which

Hub
Now replaced by switches and rarely chosen for new installations. It is still useful as a reference point for understanding how a switch works.
Switch (L2 switch)
When connecting many devices within one network. Models that support VLANs can also divide a network logically with a single unit.
Router
When connecting different networks. It sits at the LAN-internet boundary or between subnets and handles route selection, NAT, packet filtering and similar tasks.

FAQ

How does an L3 switch differ from a router?

An L3 switch is a switch with router functions (layer 3 forwarding) added, and it can relay traffic between VLANs quickly in hardware. It is mainly used inside a LAN to connect subnets and VLANs. A router typically offers a broader set of functions needed at network boundaries, such as connecting to lines that link to the internet or other sites, NAT and VPNs. The range of functions does overlap depending on the product, however.

Which of these is a home broadband router?

It combines a router, a switch, a wireless LAN access point and more in one unit. The LAN-side ports are connected to each other as a switch, while traffic between the LAN and the internet is relayed as a router, sharing one global address through NAPT. Many also act as a DHCP server.

Does using a switch reduce broadcasts?

No. A switch sends broadcast frames to every port except the one they arrived on, so they reach every connected device. What a switch divides is the collision domain. To limit how far broadcasts reach, divide the network with VLANs or with a router.

Why are hubs no longer used?

With a hub, all ports share one channel, so the more devices are connected, the more collisions occur, and the bandwidth is shared as well. In addition, all traffic flows to all ports, so devices can receive traffic addressed to others. A switch forwards only to the destination port and can communicate in full duplex on each port, so traffic between different pairs of ports can happen at the same time.

Check your understanding

In the OSI reference model, which layer uses logical addresses such as IP addresses to relay packets between different networks until they reach their destination?

  1. AData link layer (layer 2)
  2. BNetwork layer (layer 3)
  3. CTransport layer (layer 4)
Show answer and explanation

Answer: B. Network layer (layer 3)

The OSI reference model organizes communication functions into seven layers, from the physical layer up to the application layer. The network layer (layer 3) uses logical addresses such as IP addresses to choose a route across multiple networks and relay packets to the destination. The data link layer below it only delivers frames to a neighboring device within the same network, using MAC addresses. The transport layer handles communication between applications on the end hosts; TCP, for example, manages retransmission and ordering. In terms of equipment, routers operate at layer 3 and L2 switches at layer 2.

Compared with a hub (repeater hub), which correctly describes how an L2 switch operates?

  1. AIt reads IP addresses and relays packets between different networks
  2. BIt reads the destination MAC address of a frame and forwards it only to the port where the destination device is connected
  3. CIt always sends every frame to all ports, and only the destination device accepts it
Show answer and explanation

Answer: B. It reads the destination MAC address of a frame and forwards it only to the port where the destination device is connected

A hub is a layer 1 device that repeats the signal arriving on one port to all ports. All attached devices therefore share one channel, and simultaneous transmissions collide. An L2 switch is a layer 2 device: it records which source MAC address arrived on which port in a table (the MAC address table) and forwards each frame only to the port where its destination MAC address is connected. Frames for destinations not yet in the table, and broadcast frames, are sent to all ports except the one they came in on (flooding). Because traffic is separated per port, communication between different pairs of ports can happen at the same time. Relaying between different networks based on IP addresses is the job of a router at layer 3.

On one L2 switch, VLANs are configured so that ports 1–4 are in VLAN 10 and ports 5–8 are in VLAN 20. Which statement about its operation is correct?

  1. ABecause VLAN 10 and VLAN 20 are on the same switch, they can communicate directly without a router
  2. BSplitting into two VLANs halves the speed of each port
  3. CBroadcasts sent by devices in VLAN 10 do not reach VLAN 20 ports, and traffic between VLAN 10 and VLAN 20 needs a router (or L3 switch)
Show answer and explanation

Answer: C. Broadcasts sent by devices in VLAN 10 do not reach VLAN 20 ports, and traffic between VLAN 10 and VLAN 20 needs a router (or L3 switch)

A VLAN (virtual LAN) creates logically separate networks on the same physical equipment, typically on a per-port basis. Each VLAN has its own broadcast domain, the range a broadcast reaches, and the switch forwards frames only between ports in the same VLAN. Traffic between different VLANs, such as VLAN 10 and VLAN 20 in this example, must therefore pass through a router or L3 switch that relays it at layer 3. When VLANs span several switches, a tag (VLAN ID) defined by IEEE 802.1Q is inserted into frames to indicate which VLAN they belong to. VLANs are used to separate networks by department, or to isolate a guest wireless LAN from the internal network.

  1. A host (192.168.1.10/24, default gateway 192.168.1.1) sends a packet to server 203.0.113.80 on a different network. With an empty ARP cache, whose MAC address does the host look up with ARP?
  2. A router's routing table has four routes: 0.0.0.0/0 (next hop router A), 10.0.0.0/8 (router B), 10.1.0.0/16 (router C) and 10.1.2.0/24 (router D). To which router is a packet for 10.1.5.9 sent?
  3. Which correctly describes dynamic routing?

Practice Computer Networking Basics questions

Key terms explained

OSI reference model
A model that organizes communication functions into seven layers: physical, data link, network, transport, session, presentation and application. It serves as a common vocabulary for thinking about each layer's role separately.
MAC address
The 48-bit address used in Ethernet and wireless LAN to identify devices within the same network. The upper 24 bits identify the manufacturer, and it is assigned to each interface at manufacture.
VLAN
Virtual LAN. A function that creates logically separate networks (broadcast domains) on the same physical equipment, typically per switch port. Between switches, VLANs are distinguished by IEEE 802.1Q tags.
ARP
Address Resolution Protocol. A protocol that finds the MAC address of a device on the same network from its IP address. The request is broadcast, and the matching device replies.
Default gateway
The router to which a host hands packets for destinations on other networks. The host uses its subnet mask to decide whether a destination is on the same network, and sends to this router if not.
NAT (Network Address Translation)
A technique that rewrites the IP addresses of packets passing through a router. The variant that also rewrites port numbers so many devices can share one global address is called NAPT (IP masquerading).
Subnet mask
A 32-bit value that shows how many upper bits of an IP address represent the network (the network part). Written like 255.255.255.0, which means the same as /24 in CIDR notation.

Related comparisons