# Switch
## What is a Switch
A switch is a network device that operates at the Data Link layer of the OSI model, though some advanced switches also operate at the Network layer. A switch connects multiple devices within a local area network and uses MAC addresses to intelligently forward data only to the device for which it is intended. Unlike a hub that broadcasts all data to all ports, a switch sends data only to the specific port connected to the destination device. This makes switches much more efficient than hubs and is why they have almost completely replaced hubs in modern networks.
## How a Switch Works
A switch maintains a MAC address table, also called a Content Addressable Memory table or CAM table. When a switch receives a frame, it reads the source MAC address and records it in the MAC address table along with the port number on which the frame was received. This is how the switch learns the location of devices. When the switch needs to forward the frame, it looks up the destination MAC address in the MAC address table. If the destination MAC address is found, the switch forwards the frame only to the port associated with that MAC address. If the destination MAC address is not yet in the table, the switch floods the frame out all ports except the port it was received on, similar to how a hub behaves. As devices respond, the switch learns their MAC addresses and adds them to the table.
## Full Duplex Communication
Modern switches support full-duplex communication, meaning devices can simultaneously send and receive data without waiting for the link to be idle. In a hub-based network, devices must take turns transmitting to avoid collisions. In a switch-based network with full duplex, there are no collisions because each device has its own dedicated connection to the switch port.
## VLANs and Managed Switches
Managed switches offer advanced features including Virtual LANs or VLANs. VLANs allow the network administrator to logically divide a single physical switch into multiple separate virtual networks. Devices in different VLANs cannot communicate directly with each other without going through a router, even if they are connected to the same physical switch. This provides improved security and allows traffic from different departments to be separated without requiring separate physical switches.
## Layer 3 Switches
Some switches are capable of performing routing functions in addition to switching, operating at both Layer 2 and Layer 3 of the OSI model. These Layer 3 switches can route traffic between different VLANs without requiring a separate router, improving performance in networks with many VLANs.Back to Subject