No, switches are not just simplified routers. Although many devices combine functions of both routing and switching, the two functions are distinct. Switches create networks, routers connect distinct networks together. Switches operate using only MAC-addresses, while routers also use IP addresses. Switches have many ports in the same subnet, while routers can only have one port per subnet. Devices that combine these functions still maintain a distinction between routing and switching, as they will separate 'switched' ports from 'routed' ports due to the requirements of the different functions and hardware.
To show some of the nuances: professional grade routers will perform internal switching functions (such as CEF), and some 'layer 3' switches Route (if they are layer-3 switches), but the operations are distinct.
It is useful for anyone interested in networking to become familiar with the OSI Model, which describes how computers and other devices talk to each other. The OSI Model breaks communication into seven layers, including the Application layer, which is the program you, the human, are working with, the Network layer or Layer-3, which deals with IP addresses and Routing, and the Data Link layer, or Layer-2, which deals with physical hardware addresses. Also, when you hear terms like TCP, ports, sockets, sessions, etc., these are also represented by the OSI model, so it's useful to learn.
Routers operate with IP addresses at the OSI Layer-3 or Network Layer and Switches operate with MAC addresses at the OSI Layer 2 or Data Link Layer.
Some devices, such as consumer wifi-routers, combine both a switch and a router in the same device (for instance a wifi router with 5 extra ports on the back). Other devices, such as cable or DSL modems, still function as a router because they route packets between your local network, and the remote network, and perform layer-3 functions such as NAT.
The operations of Routing and Switching are distinct however, and operate on different layers of encapsulation, different OSI layers, and with different addresses, as described below:
In detail:
Switching
We will start with a Layer-2 Switch. This is your standard switch, that includes all un-managed switches, and even managed switches that only operate at the Data-Link layer. This switch receives frames and compares them to a MAC-Address-Table (which is distinct from the ARP table in that it has MAC Addresses and Ports, rather than MACs and IPs). It uses this information to forward frames either to one, many, or all ports depending on whether it is a unicast, multicast, or broadcast frame. If it is a unicast frame, but it does not know which port to send it to, it floods it to ALL ports, except the port the switch received the frame on. Of course there is more detail with CAM tables and VLANS, but in short: Switching moves frames based on hardware addresses, switching can only move frames within the same subnet.
Routing
A router routes between subnets. In fact, on a router, you cannot put multiple routed interfaces on the same subnet - because a routers function is to move packets between layer-3 subnets. The router thus receives frames, containing packets off a port. If frame's destination (mac-address) matches the router (either as unicast or broadcast), the router will then look at the IP-packet contained inside the frame, and make a routing decision based on the IP and subnets. Once the routing decision is made, a switching decision is made to determine which port and layer-2 destination to send the packet to, so it can be re-encapsulated at Layer-2. For more information about the switching conducted by the router, see Cisco Express Forwarding, for example.
How the computer gets through the gateway:
So how does the computer reach its gateway? The computer itself has a route to its gateway. It knows that "if an IP is not on my subnet, I need to send the packet to this gateway address to get out," Thus, since all devices process top-down through the OSI-model, the computer will do an internal routing lookup first (layer-3) to decide wither a device is within its subnet. If not, it will arp (layer-2) to find the mac-address of the default gateway, and will encapsulate the IP packet for the remote host within a frame addressed to the router. The frame will be switched across the network using layer-2 headers and MAC addresses, within the same subnet, until it reaches the router, where its layer-3 IP addresses are looked at, and the decapsulated packet is routed between subnets.
Layer-3 Switches
The other scenario I haven't covered is the Layer 3 switch. These switches operate the same way as described above. They are switches, but they can have specific ports, physical or virtual, designated as routed ports. These routed ports operate as gateways between subnets, (often VLANs within a switch) while the switched ports continue to only operate at Layer-2.
Part of the distinction between layer-2 and layer-3 devices is reflected in the hardware and memory of the devices. As Cisco explains, layer-2 only devices have a CAM (content addressable memory) table containing the MAC-Address-table. Layer-3 devices additionaly have a TCAM table, which handles mapping between routing, layer-2 and layer-3 addresses. Because of the physical hardware differences, you will see price differences in hardware that is a pure layer-2 switch, a layer-3 switch, and a router.
Thank you for an in depth answer! If we have a local network built with multiple switches (layer 2), they will "slowly" build up a MAC table. So each computer on this network will need to know every computers MAC to be able to communicate? So if it knows the IP of a computer, it needs to map that to a MAC first? – Friend of Kim – 2014-11-25T15:08:34.247
So if the IP is not on the subnet, the computer will have to know the MAC address of the router which is connected to the internet? And the actual packet containing the recipients IP is wrapped inside another packet with a MAC address as the recipient (router)? – Friend of Kim – 2014-11-25T15:09:16.383
1The computer has to know the MAC of the Gateway, which is the router, yes. It can find this out through and ARP request. This is why when you do DHCP, or manually configure a computer's IP, it asks you for the IP of the gateway. Given the IP, it can find the MAC. ... Once the router receives the frame, it RE-ENCAPSULATES it, or wraps it, inside of a new frame on the remote network, containing the source MAC of the router, and the destination MAC of the remote computer. – glallen – 2014-11-25T15:14:00.037
So all the switch does is make it possible for computers to communicate locally? Like a hub that doesn't send every package everywhere. The router is the device that actually understands IP and uses it to route the package to the correct network. – Friend of Kim – 2014-11-25T15:18:15.393
So if a home user were to use a switch instead of a router. Would this be possible by setting the default gateway on each computer to the gateway of the ISP? So let's say the entire neighborhood were all connected to the same ISP switch, they would be able to communicate through MAC addresses? – Friend of Kim – 2014-11-25T15:23:24.310
1
Somewhere, there is a router. Whether it is your router, or the ISPs. A cable/DSL modem acts as a router, because it provides a local subnet for your home, provides a gateway address, and routes to external networks. If the whole neighborhood was in the same subnet, they could communicate with IPs within that subnet. The OSI Model still applies, the computers will still want layer-3 addresses. The exception is with point-to-point modem or serial links, which are rare these days.
– glallen – 2014-11-25T15:39:20.690Thank you for your answers! Now I see how they are different devices entirely. Well explained! – Friend of Kim – 2014-11-25T15:54:41.837
+1 - Another excellent answer. Could I trouble you with a minor nit? Your answer assumes the reader has a certain base level of knowledge. Could you add a couple of sentences near the beginning to set up your answer? Explain briefly what a "layer" is and the functions of layer 2 and layer 3. Then the references to them will be more understandable by readers with little knowledge of networking. – fixer1234 – 2014-11-25T16:07:08.887
@fixer1234 Done. Thanks for the pointer. – glallen – 2014-11-25T17:24:43.017
"Yes, but no:" <-- so you begin with a very confusing nonsensical beginning. You then write "Routers often switch (internally)" <-- There are devices that people call routers that aren't just routers. You write "Switches sometimes Route (if they are layer-3 switches)" <-- From what I understand(having looked into it many times), they're not switches, they're routers that are being marketted as switches. (with the justification that they use some different hardware to implement the routing, but really the type of chips/silicone/whatever they use is irrelevant) – barlop – 2014-11-25T17:31:01.147
1Well, internally a cisco router for instance uses CEF and CAM tables to do mac-to-port translations after it has done it's routing lookups, then it uses these tables to avoid having to do the routing decisions again for subsequent packets with the similar headers, and effectively switches. Maybe not with a unmanaged netgear switch, but with managed enterprise networking hardware it does become nuanced. My answer reflects this. – glallen – 2014-11-25T17:34:08.197
Layer three switches are routers, and they are switches. Routers don't have switching ASICs and you can put a port in switch port mode, unless you add a switching module. Layer-3 switches still make the distinction between switched and routed ports, you have to specify which is which, you can't have two routed ports on the same subnet for instance, and different hardware handles each function depending on the mode.
– glallen – 2014-11-25T17:36:55.680@barlop I think my last edits should clarify a bit. – glallen – 2014-11-25T18:10:54.863
@glallen yes your edit is a good improvement. Your comments are interesting, I haven't had that much experience with cisco stuff. – barlop – 2014-11-25T18:28:51.573
1It's hard to be simple, ++1 for "switches create networks, routers connect distinct networks together" – elsadek – 2016-01-08T17:07:01.493