A network switch connects devices within a LAN, facilitating communication by directing data packets between devices on the same network. It operates at the data link layer (Layer 2) of the OSI model. A router, however, connects multiple networks together, such as a LAN to the internet, and directs data packets between them. It operates at the network layer (Layer 3), making decisions based on IP addresses.