A switch is a multi-port bridge, meaning that it is an active element working on layer 2 of the OSI model.
The switch analyzes the frames coming in on its entry ports and filters the data in order to focus solely on the right ports (this is called switching and is used in switched networks). As a result, the switch can act as both a port when filtering and as a hub when handling connections. Here is a diagram of a switch:
The switch uses a filtering/switching mechanism that redirects data flow to the most suitable machines, based on certain elements found in the data packets.
A layer-4 switch, operating on the transport layer of the OSI model, inspects the source and destination addresses of the messages, and creates a table that lets it find out which machine is connected to which port on the switch (in general this process is done automatically, but the switch manager can work differently if the right adjustments are made).
Once it knows the destination port, the switch only sends the message to the right port, and the other ports are then free for other transmissions which may be taking place at the same time. Consequently, each data exchange can run at the nominal transfer rate (more bandwidth sharing), without collisions, with the end result being a very significant increase in the network's bandwidth (at an equal nominal speed).
The most advanced switches, called layer 7 switches (corresponding to the application layer of the OSI model) can redirect data based on advanced application data contained in the data packets, such as cookies for HTTP, the type of the file being sent for FTP, etc. For this reason, a layer 7 switch can be used for load balancing, by routing the incoming data flow to the most appropriate servers, which have a lower load or are responding more quickly.