Computer Networks Interview Questions · Question 04

Differentiate between a hub, switch and router based on how they forward data.

Interview preparation resource from Gate Smashers.

Interview-ready answer

A hub repeats an incoming signal to all other ports without examining addresses. A switch forwards Ethernet frames based on the destination MAC address, sending known unicast traffic only to the associated port and flooding unknown-unicast traffic within the VLAN. A router forwards IP packets between networks by looking up the destination IP address in its routing table and sending the packet to the selected next hop or outgoing interface.

Understand it clearly

Hub forwarding

A hub operates at the physical layer. When it receives a signal on one port, it repeats that signal out all other ports. It makes no MAC-address or IP-address forwarding decision, so every connected device receives the transmission signal.

  • Data handled: Bits or electrical/physical signals.
  • Forwarding basis: No address-based decision; the signal is repeated to other ports.

Switch forwarding

A Layer 2 switch forwards Ethernet frames within a LAN or VLAN. It learns source MAC addresses and associates them with ingress ports. For a known unicast destination MAC address, it sends the frame only through the corresponding port rather than all ports.

If the destination MAC address is not in the switch's forwarding table, the switch floods the frame through relevant ports in the same VLAN, except the port on which it arrived. Broadcast traffic is also forwarded within the VLAN.

  • Data handled: Ethernet frames.
  • Forwarding basis: Destination MAC address and the switch's MAC address table, scoped to a VLAN.

Router forwarding

A router operates at the network layer and connects different IP networks. It examines the destination IP address, consults its routing table, and forwards the packet through the selected outgoing interface or to a next-hop router.

Unlike a switch, a router does not use the destination MAC address to select the end-to-end route. MAC addresses are used only for local-link delivery on each side of the router.

  • Data handled: IP packets.
  • Forwarding basis: Destination IP address and the routing table.

Traffic scope and broadcast domains

A hub and a switch do not route traffic between IP networks. A hub repeats traffic across its connected ports, while a switch limits known unicast traffic to the required port. A switch creates separate broadcast domains when ports are placed in different VLANs.

Routers separate broadcast domains and route packets between IP networks. Traffic intended for another IP network is sent to a router, which determines where to forward it next.

Quick comparison
BasisHubSwitch and Router
Forwarding decisionRepeats the received signal to all other ports; no address lookup.Switch: uses the destination MAC address. Router: uses the destination IP address and routing table.
Data unitBits or signals.Switch: Ethernet frames. Router: IP packets.
Typical OSI layerLayer 1.Switch: Layer 2. Router: Layer 3.
Traffic destinationAll other connected ports receive the repeated signal.Switch: known unicast frames go to one port; unknown unicast and broadcast traffic are flooded within the VLAN. Router: packets are sent toward a selected next hop or outgoing interface.
Network scopeDoes not connect or route between IP networks.Switch: forwards within a LAN or VLAN. Router: forwards between IP networks and separates broadcast domains.