The Short Answer:
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 are displayed as 4 numbers between 0 and 255 separated by periods. An example could be “220.127.116.11” 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.
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:
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.