A virtual switch provides connectivity between virtual machines within the same host or across different hosts. It operates at the data link layer of the OSI model to direct traffic internally within a virtualized environment, similar to how a physical switch directs packets between devices on a network.