What is the basic difference between layer 2 & layer 3 switches? We often hear of these two terms and try to distinguish them, which one is better for building our network.
To be simple, Layer 3 switches route packets based on IP, layer 2 by MAC. Both switch types have the capability of linking network devices together from one port to another. Unlike hubs, switches distribute data more intelligently as it interprets them and sends it out to the right destination.
Layer 2 and Layer 3 terms come from the OSI seven Layer model (a theoretical way of dividing network architecture up with functionality, service, dependence and application). Within the model, Layer 2 represents the “Data Link Layer” while Layer 3 represents the “Network Layer”.
Layer 2 switches have the capability of moving packets around a single network. As the reference to the OSI Layer holds true, this switch facilitates data only (and) within the physical layer (also known as Layer 1 e.g. cables and connectors). It is intelligent enough to learn the MAC addresses of each device, source/ destination of each packet and routes each packet within the single domain (at wire speed). While it breaks up a collision domain, it does not have the ability to transport the data packet from one network to another nor can it prioritize packets to guarantee bandwidth. Putting devices on a Layer 2 switch makes one entire large local segment (or what some people might call a “broadcast domain”).
Layer 3 switches act like a traditional router – it enables different network segments to be linked together. With this, data can be inter-networked from one network subnet to another. Prioritization of packets can be setup and the Layer 3 switch is intelligent enough to learn which routes are the best between the networks. While the Layer 2 switch routes packets based on MAC, Layer 3 switches route data packets based on IP. Going a step further, Layer 3 switches have the capability to logically separate networks into two or more VLANs (Virtual LANs), enhancing security and unauthorized access between networks. A Layer 3 switch typically sits above Layer 2 switches and governs the routes/ access between the different networks.
An example of this would be within a water treatment facility. Being a big treatment plant, each separate department (Clorination, Aeration, Distillation, Filtration, Waste Generation etc.) is split up into smaller/mini networks. Each mini network (consisting of PLC, I/O modules, monitors, sensors, HVAC, Historian stations and more) is controlled by its own Layer 2 switch. As all departments need the ability to synchronize, coordinate and share data with each other to perform the relevant operations, there needs to be a device that allows each data to move from one department’s network to another. That is where the Layer 3 switch comes in. All Layer 2 switches essentially converges to the Layer 3 switch facilitating inter-network data transport with the ability to prioritize packets, allow/ limit access to certain networks at any given time.
Small networks can be built using just Layer 2 devices, but most corporate networks will have a mix of Layer 2 and Layer 3 switches. Dumb Layer 2 products are a cheap and easy way of providing connectivity to workgroups while more intelligent Layer 3 switches enable departmental networks to be segmented and controlled with no loss of bandwidth.
Finally, it's worth noting that some switch vendors claim to support Layer 4 (the Transport Layer) and above. Load balancing switches, for example, use information beyond Layer 3 to distribute packets across large server farms. However, there's blurring of the levels in these more sophisticated products such that it's now more usual to refer to them as multi-level switches. Multi-level switches are more expensive and complicated to deploy and mostly reserved for specialist applications.
The Cisco Catalyst 2950, Cisco 2960 series are typical examples of Layer 2 switches. The Cisco Catalyst 3550, 3560, 3750, 4500, 6500 series would be good examples of Layer 3 switches.