Course contents

Unit 2: Network DevicesLesson 2.9 (9 of 10 in this unit)14 of 104 in the Network Fundamentals course

Routing vs Switching

Switches and routers both move data, which is why they get confused. The difference is what each one reads, which table it uses, and where its job ends. Once you see that, most network designs make sense.

Beginner · 9 min read · Before this: Switches, Routers

Covers Layer 2 and Layer 3, MAC table and routing table, Broadcast domains and What changes on a hop.

Technical definition

Switching and routing are the two ways a network moves traffic. A switch forwards frames inside one network using MAC addresses at Layer 2. A router forwards packets between networks using IP addresses at Layer 3.

Switching stays in the LAN, routing crosses between networks
Switching stays in the LAN, routing crosses between networksPC1 at 10.0.1.10 sends to PC2 at 10.0.1.20 on the same network through a switch. The switch reads the destination MAC address and forwards the frame unchanged. PC1 then sends to a server at 10.0.2.10 on another network. PC1 sends the frame to its gateway router. The router reads the destination IP address, picks the next hop from its routing table, and rewrites the MAC addresses on the way out while the IP addresses stay the same.Switching: same networkRouting: between networksPC1SW1PC2Reads: destination MACTable: MAC address tableFrame leaves unchangedStops at the network's edgeFrame, PC1 to PC2src MAC: PC1 dst MAC: PC2src IP 10.0.1.10 dst IP 10.0.1.20both pairs identify the same two hostsPC1R1ServerReads: destination IPTable: routing tableRebuilds the frame header for the next hopSeparates broadcast domainsPC1 to R1src MAC: PC1dst MAC: R1src IP 10.0.1.10dst IP 10.0.2.10R1 to serversrc MAC: R1dst MAC: serversrc IP 10.0.1.10dst IP 10.0.2.10

On small screens, swipe sideways or focus the diagram and use the arrow keys.

A switch reads the MAC address and leaves the frame alone. A router reads the IP address, drops the old frame header and builds a new one for the next link. The IP source and destination stay the same end to end.

What each one reads

A switch looks at the destination MAC address in the Ethernet frame and uses its MAC address table to send the frame out the right port. A router looks at the destination IP address in the packet and uses its routing table to choose the next hop and the outgoing interface.

Routing and switching compared
Routing and switching compared; Switching; Routing. OSI layer: Layer 2, data link Layer 3, network Forwards by: Destination MAC address Destination IP address Learns from: Source MACs of frames it sees Static routes and routing protocols Table: MAC address table Routing table Scope: Inside one network or VLAN Between networks Broadcasts: Floods them within the VLAN Does not forward themSwitchingRoutingOSI layerLayer 2, data linkLayer 3, networkForwards byDestination MAC addressDestination IP addressLearns fromSource MACs of frames it seesStatic routes and routing protocolsTableMAC address tableRouting tableScopeInside one network or VLANBetween networksBroadcastsFloods them within the VLANDoes not forward them

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Header row, topics and answers use different colours so each row reads across.

What changes when a frame crosses a router

A switch forwards the frame as it is. A router receives the frame, removes the Layer 2 header, checks the IP packet, chooses the next hop, and builds a new frame for the next link. The MAC addresses change at every hop, because each link is its own network. The IP addresses stay the same, which is how the two hosts identify each other end to end.

Broadcast domains

A switch floods broadcasts to every port in the same VLAN, so all those ports share one broadcast domain. A router does not forward broadcasts, so each routed interface is a separate domain (see Broadcast domains). That is why large networks are divided into several routed networks: it keeps broadcast traffic local.

Using them together

Hosts on the same network reach each other through switches. When the destination is on another network, the host sends the frame to its default gateway, the router, which forwards it onward (see The default gateway). Real networks use both: switches to connect hosts, routers to connect networks.

Test yourself

Predict · scenario 1

A frame goes from PC1 to PC2 on the same VLAN through one switch. What does the switch read to forward it?

Predict · scenario 2

A packet crosses a router. Which values stay the same from source to destination?

Predict · scenario 3

Which device separates broadcast domains by default?

FAQ

Can a switch route?
A Layer 2 switch cannot. A Layer 3 switch can route between VLANs and networks as well as switch inside them. See Router vs Layer 3 switch.
Does a router change the IP addresses in a packet?
Normally not. A router rewrites the Ethernet header for each link, but the source and destination IP addresses stay the same end to end, unless NAT translates them.
Why does a router stop broadcasts?
A router forwards by IP destination and does not forward Layer 2 broadcasts, so each of its interfaces is its own broadcast domain.