What is the difference between a router and a switch

The Short Answer:

switch-router

To Diagram, use Circles for Routers, Squares for Switches

So, what is the difference between a router and a switch? A router deals with IP addresses.  Using IP addresses to decide what to do with the traffic it is seeing.

A switch deals with MAC (Media Access Control, aka hardware/physical) addresses.  Using MAC addresses to decide what interface to send traffic out.

The Extended version:

Lets talk about IP and MAC addresses for a minute to better understand “the short answer” above.

IP Addresses:

IP addresses are displayed as 4 numbers between 0 and 255 separated by periods.  An example could be “8.8.8.8” or “10.32.24.1”.  These numbers have a specific structure to them that is used by routers.  Every system on the internet has a “unique” IP.  There is a network mask that goes along with the IP that tells routers how to break the number down into pieces.  IP addresses are normally assigned to you by your ISP.  There are, however, some IP network ranges that anyone can use.  The problem with these numbers is that they can only be used within your own network.  These networks will not be routed by internet service provides so if you use these IP’s on your network, you will need to use something called NAT to enable the computers on your network to access the internet.

Please note that these addresses are part of the IPv4 specification.  IPv4 has been around for a while and is what most of us are using right now.  IPv6 is a new kid on the block.  It isn’t as widely used (yet) so we will forgo discussing it for now.  You can check out my IPv6 blog posts to learn more about IPv6.

IP addresses are like your street address. They relate to where you are and change when you move.

MAC Addresses:

The MAC address is a number that network card manufactures assign to every card they produce (wired, wireless, etc.).  Switches listen for this address when a computer talks on the network.  It will take note of which port that MAC address was seen on and any traffic going to that MAC address will be sent out just that one port.  This keeping track of where every computer is sitting on the network helps the network send traffic only to the ports that need the traffic, making the network more efficient.

MAC addresses are like your name. Once you have been given one it doesn’t change, whether you live in London or Sydney.

So why both IP and MAC?

The network uses both because it has a need to manage traffic quickly, minimize how much information it has to know to work, and a need to talk to any given computer on the planet on a whim.  The MAC address is really only used locally on a network.  You computer knows and/or can figure out the MAC addresses of nearby computers and network equipment (like routers).  It doesn’t need to know the MAC of all the computers on the internet, just the local ones.

To talk to computers that are on the internet your computer uses an IP address.  Normally, it will use DNS to convert a name like www.computernetworkbasics.com into an IP address.  Then it uses that IP address as the destination for packets it is sending to the website.

MAC addresses are nearsighted and IP addresses are Farsighted.

The traffic flows like this:

Relay Race

Relay Race: People are MAC addresses, the Baton is the IP.

Your computer figures out that the IP address is on another network so it sends a packet containing the destination IP address but (here is the tricky part) with the local routers MAC address.  This is “switched” over to the router, who looks to see if it knows what to do with that packet based on its IP address.  Once it makes a decision it will send the packet to the next router using its own MAC and the next routers MAC but keeping the original source and destination IP addresses.  This process creates magic and, wha-la, you are able to talk to this website and pull this webpage down to view it.

MAC addresses travel like a relay race while IP addresses travel like a marathon runner.

What other aspects of computer networking do you have questions about?  Drop me a line or make a comment below.

4 Responses to What is the difference between a router and a switch

  1. a little history.

    routers typically forwards packets based upon layer 3 (network layer) addresses. Other information may be used to handle or block the packets, but to determine where the packet is to go next, typically the destination network layer host/network address is used.

    _BRIDGES_ typically forwards packets based upon layer 2 (network layer) addresses.

    repeaters use layer 1 (physical layer) to relay those signals.

    “switches” were/are ‘things’ that can forward information/data at the line rate for the aggregate of all its physical interfaces.

    bridges didn’t start being called switches until they forward at or near interface speed and marketing/sales folks thought it sounded faster or implied faster operations.

    For bonus history points,

    difference between a router and a gateway

    other network layer protocols such as: IPX; AppleTalk; DECnet (phase IV and-or phase V); ChaosNet; …

    bit order in presented mac addresses. why is bit 47 in bit 40’s place? ieee canonical vs token ring mac address formats.

    Just an old timer piping in a little history; hope you don’t mind.

    • dcj,

      Thanks for tossing out the extra information. Your input is appreciated and you are absolutely right… Routers are layer 3 devices, Switches and Bridges are layer 2, and Repeaters and Hubs are layer 1. The article, however, is short on this information because my target audience isn’t always aware of the OSI reference model. So, I skirted the jargon a little. 😉

      I’d like to take a second and expand on your point about bridges vs switches for a moment. I would point out that switches are often line speed, though that isn’t a requirement to be called a switch. Another difference between bridges and switches is port count. Bridges are often 2 ports (one on each side of the bridge) where switches have many ports. Usually 24 or 48, but I’ve run switches with ports anywhere from 8 to 288. In todays world bridges aren’t often seen as a physical devices anymore though they are used in concept. The most common use I’ve come across are transparent firewalls. Here bridging is used to link 2 VLAN’s together to allow for the same subnet to exist within separate security zones.

      Thanks again for you comments.

Leave a Reply

Your email address will not be published. Required fields are marked *