Switches operate in a fundamentally
different way than hubs. Signals that enter a hub's port are
indiscriminately repeated to the hub's other ports. Switches
read both the source port and the destination port of each frame and
switch messages between the two.
A switch is able to perform more router like duties than hubs within LANs because
Historically, switches have been considered to be devices that operate on layer 2 - the data link layer of the OSI Reference Model. Remember, routers operate pretty much exclusively at layer 3 - the network layer. More recently switches that operate on layer 3 and layer 4 are being used quite a bit more often. This really blurs many of the distinctions between switches and routers.
It is important to remember there are going to be advantages and disadvantages for operating at particular layers of the OSI model. For example, when operating at layer 2 switches don't need to dig as deep to get the location to which they should be sending the frames/message as routers do.
It is turning out that switches are becoming viable replacements for hubs at the low end and routers at the higher end. Switches are replacing hubs because switches allow the network to implement higher bandwidth. They are also often replacing routers because they are inherently faster. Thus there is a push to replace routers with switches when viable. This seems to be most frequently occurring on backbones that connect LANs within a building or campus. In other locations it occurs selectively because switches are usually about 30 to 40 percent more expensive than hubs. The rule of thumb is becoming, "Switch where you can, route when you must."
Switches use one of two switching schemes.
Now we present a survey of switching where the switches are categorized according to the layer of the OSI model on which they operate.
Layer 2 Switching. With layer 2 switches all devices on the LAN segment have a direct path to the switch into a port. When a switch receives a frame/message rather than broadcasting it through all of its ports it determines which port it should send it through based on the MAC - Media Access Control address. When it receives a message seeking an address it doesn't know, instead of dropping the message it broadcasts it to all of its ports.
While switches rely on MAC addresses to locate the destination, which are essentially like serial numbers, they are often within the switch's dynamic address table. If the destination MAC address isn't there then a switch can be set up to explore and map the surrounding neighborhood or access the dynamic address tables of other nearby switches. It is also possible to configure switch servers that support extremely large dynamic MAC address tables and best routes. So particularly if you are moving messages within certain parts of an organization with known MAC addresses you are more likely to get better performance from switches. Routers are required for more open ended moves using IP addresses to more remote locations.
Some of the main advantages of using layer 2 switches are given in the following list.
It is also possible to have switches that connect an entire LAN segment to each port. These are called segment switches. These can be used in a hierarchical or cascading fashion to interconnect networks within organizations.
Switches can also be used to create VLANs - Virtual LANs which divide a physical network into multiple logical networks. Using these can improve both performance and security.
Layer 3 Switching. Layer 3 switches are essentially routers with some other capabilities. They are often called switched routers. They were initially developed to integrate switching and routing device capabilities to reduce the number of devices needed for network functionality.
Layer 3 switches perform the same functions as the layer 2 switches but also perform most of the router's functions. The switch uses a hardware based architecture to apply policies based on network layer information in the packet header.
Layer 3 switches are generally easier to setup and configure than routers and can replace routers in many situations. They are also generally less expensive than routers.
Layer 4 Switching. Recent enhancements to layer 3 switches allow them to make use of additional information from the TCP and UDP headers at layer 4 of the OSI model. Some times these switches are capable of also making use of information from even higher layers of the OSI model.
These can be worthwhile when doing things like filtering access through an ACL - Access Control List. They might also be used to manage allocation of bandwidth for QoS - Quality of Service implementations or perform load balancing.
These functions are also available on many modern routers.