The practical difference between a switch and a router is what you plug in to each one. Switches are sold for the purpose of connecting many devices, such as servers, PCs, and printers. Routers have increasingly become specialized in routing packets between physical sites, as well as to and from the Internet, at scales ranging from small home networks to the largest data centers in the world.
When you buy a switch, you typically look at the number of ports it supports, the speed of those ports, and what kind of virtual networking the switch enables. Many switches also have basic routing capabilities; routers can route far larger numbers of packets than switches and increasingly support additional capabilities, such as data security.
Traditionally, the difference between a switch and a router was that switches could only forward packets based upon Layer 2 MAC addresses, while a router could route packets based on Layer 3 addresses like IP. In practice, this meant that switches connected a single LAN together, while routers connected multiple LANs, multiple physical locations, and/or offered connectivity to the Internet. This has changed.
In the context of modern networking, the difference between a switch and a router is largely about the primary purpose of the device. Today’s advanced switches support virtual networks and can route packets between different virtual and physical LANs. This means today’s switches can route packets based on both Layer 2 and Layer 3 addresses, just like routers can.