A switch is a networking device that is used to connect multiple devices within a Local Area Network (LAN), where it receives data from one device and forwards it only to the intended destination device by using MAC addresses, which helps in reducing unnecessary traffic and improving overall network performance as compared to older devices like hubs.

🧠 Basic Idea
👉 Switch = Connect devices + Intelligent data forwarding
In a network, a switch acts as a central connecting device that allows communication between multiple devices such as computers, printers, and servers, while improving network performance by reducing unnecessary traffic.

A switch works by learning and storing MAC addresses of connected devices in a table called the MAC Address Table (or CAM Table), and when data arrives, it checks the destination MAC address and forwards the data only to the specific port where the destination device is connected.
The MAC address table is a database maintained by the switch that stores the mapping between MAC addresses and switch ports, which helps the switch to make forwarding decisions efficiently.
Example
| MAC Address | Port |
| AA:BB:CC | Fa0/1 |
| DD:EE:FF | Fa0/2 |
A switch forwards data frames from the source device to the destination device by checking the destination MAC address and sending the data only to the correct port instead of broadcasting it to all ports.
Whenever a device sends data, the switch learns the MAC address of that device and stores it in a table along with the port number, which helps the switch in making future forwarding decisions quickly.
A switch filters unnecessary traffic by ensuring that data is sent only to the required device, which reduces network congestion and improves efficiency.
If the destination MAC address is not found in the MAC table, the switch sends the frame to all ports except the incoming port, which is called flooding.
Switches use protocols like STP (Spanning Tree Protocol) to prevent network loops, which can otherwise cause broadcast storms and network failure.
Switches support VLANs, which allow logical segmentation of the network into different groups without changing physical connections.
Switches provide several advantages in modern networks by improving performance and efficiency.
Switches are mainly classified based on the OSI layer on which they operate, and each type has different capabilities.
A Layer 2 switch operates on the Data Link Layer of the OSI model and uses MAC addresses to forward data within the same network, making it suitable for communication within a single LAN.
A Layer 3 switch operates on both the Data Link Layer and the Network Layer, which means it can perform switching as well as routing, allowing communication between different networks or VLANs.
A VLAN (Virtual Local Area Network) is a logical method of dividing a physical network into multiple smaller networks, where devices are grouped together based on their function, department, or requirement instead of their physical location, allowing better control over network traffic, improved security, and efficient management without changing the physical connections.
👉 VLAN = Logical separation of one network into multiple networks
In a traditional network, all devices connected to a switch belong to the same broadcast domain, which means every broadcast message is received by all devices, leading to unnecessary traffic and reduced performance, so VLAN is used to divide the network into smaller broadcast domains to improve efficiency and reduce congestion.
A VLAN works by assigning switch ports to specific VLAN IDs, and devices connected to those ports become part of that VLAN, where each VLAN behaves like a separate network, and communication is allowed only within the same VLAN unless a routing device is used.
Consider a company where different departments such as Sales and HR are connected to the same switch, but using VLAN:
Even though both departments are physically connected to the same switch:
👉 Communication between VLANs is not possible without routing
VLAN provides several advantages in modern networking by improving performance and security.
👉 VLAN = One switch → Multiple logical networks
VLAN configuration on a switch is performed by creating VLANs and assigning switch ports to those VLANs so that connected devices become part of a specific logical network.
vlan <vlan-id>
name <any-name>
exit
interface <interface-name>
switchport mode access
switchport access vlan <vlan-id>
Switch> enable
Switch# configure terminal
In this step, a VLAN is created using a VLAN ID and a name (any suitable name can be given).
Switch(config)# vlan <vlan-id>
Switch(config-vlan)# name <any-name>
Switch(config-vlan)# exit
After creating the VLAN, assign it to a specific interface so that the connected device becomes part of that VLAN.
Switch(config)# interface <interface-name>
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan <vlan-id>
If multiple ports need to be assigned to the same VLAN, interface range can be used.
Switch(config)# interface range <interface-range>
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan <vlan-id>
Repeat the same steps to create and assign additional VLANs.
show vlan brief
In this topology, a multilayer switch is used to create two VLANs to separate different departments logically:
Devices are connected to the multilayer-switch and assigned to their respective VLANs so that communication happens only within the same VLAN.

Switch> enable
Switch# configure terminal
Switch(config)# vlan 150
Switch(config-vlan)# name SALES-DEPT
Switch(config-vlan)# exit
Switch(config)# vlan 160
Switch(config-vlan)# name FINANCE-DEPT
Switch(config-vlan)# exit
Switch(config)# interface fa0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 150
Switch(config)# interface fa0/2
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 150
👉 (Ports connected to Laptop0 and PC0)
Switch(config)# interface fa0/3
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 160
Switch(config)# interface fa0/4
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 160
👉 (Ports connected to Laptop1 and PC1)
show vlan brief
👉 🖼️(Place VLAN Verification Image Here)
👉 Same Switch + Multiple VLANs =
Logical separation of departments
In this topology, VLANs are configured on a multilayer switch to separate Sales and Finance departments into different networks, where ports are assigned to specific VLANs, ensuring that devices communicate only within their own VLAN.
Inter-VLAN Routing is the process of enabling communication between devices that are present in different VLANs, where a Layer 3 device such as a router or multilayer switch is used to route traffic from one VLAN to another, because VLANs are separate networks and cannot communicate directly with each other.
👉 Inter-VLAN Routing =
Communication between different VLANs using routing
In a VLAN-based network, each VLAN acts as a separate broadcast domain, which means devices in different VLANs cannot communicate directly, so Inter-VLAN Routing is required to allow communication between these VLANs when needed.
Inter-VLAN Routing works by using a Layer 3 device that has interfaces or virtual interfaces for each VLAN, where the device receives data from one VLAN, checks the destination IP address, and then forwards the data to the correct VLAN, enabling communication between different networks.
Inter-VLAN routing provides several advantages by enabling communication while maintaining network segmentation.
ip routing
interface vlan <vlan-id>
ip address <gateway-ip> <subnet-mask>
no shutdown
Switch> enable
Switch# configure terminal
In this step, routing is enabled on the multilayer switch so that it can perform Layer 3 operations.
Switch(config)# ip routing
For each VLAN, a virtual interface is created so that the switch can act as a gateway for that VLAN.
Switch(config)# interface vlan <vlan-id>
Switch(config-if)# ip address <gateway-ip> <subnet-mask>
Switch(config-if)# no shutdown
The same process is repeated for all VLANs to enable communication between them.
Ports must be assigned to VLANs so that devices become part of the respective VLANs.
Each device must use the VLAN interface IP as its default gateway.
show ip route
show vlan brief
show ip interface brief
In this topology, a multilayer switch is used to create two VLANs for different departments, and Inter-VLAN routing is configured so that devices from different VLANs can communicate with each other through the switch acting as a Layer 3 device.

Switch> enable
Switch# configure terminal
Switch(config)# vlan 150
Switch(config-vlan)# name SALES-DEPT
Switch(config-vlan)# exit
Switch(config)# vlan 160
Switch(config-vlan)# name FINANCE-DEPT
Switch(config-vlan)# exit
Switch(config)# interface fa0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 150
Switch(config)# interface fa0/2
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 150
Switch(config)# interface fa0/3
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 160
Switch(config)# interface fa0/4
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 160
Switch(config)# ip routing
Switch(config)# interface vlan 150
Switch(config-if)# ip address 192.168.150.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config-if)# exit
Switch(config)# interface vlan 160
Switch(config-if)# ip address 192.168.160.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config-if)# exit
IP Address: 192.168.150.x
Subnet Mask: 255.255.255.0
Gateway: 192.168.150.1
IP Address: 192.168.160.x
Subnet Mask: 255.255.255.0
Gateway: 192.168.160.1
🔍 Check VLAN : show vlan brief

👉 Ping from Sales VLAN → Finance VLAN
ping 192.168.160.2

👉 VLAN + Inter-VLAN Routing =
Separation + Communication
In this topology, VLANs are configured to separate departments, and Inter-VLAN routing is enabled using a multilayer switch so that devices from different VLANs can communicate efficiently.