A switch is a networking device used to connect multiple devices like computers, printers, IP phones, etc., in a Local Area Network (LAN). A switch is actually more intelligent compared to a hub because it knows which port is connected to which device. So, it sends data to the specific recipient.
Where Switch is used?
It can be used anywhere where the devices being used need to be connected. For example, in schools, colleges, offices, and businesses — to connect desktops, PCs, smart boards, CCTV cameras, file servers. It is also used in data centres, hospitals, shopping malls, government offices, and even at home (within routers).
How a Switch Works
As I said earlier, a switch is more intelligent than a hub. Let’s see in what way and how a switch functions. First, we will take a simple look at how a hub works. When any device sends data to another device, the data packets are received by the hub and broadcast to all the ports — i.e., to all the devices connected to the hub. This is what happens whenever devices communicate with each other in a LAN connected via a hub.
When a data packet comes to a switch, it reads the MAC address of the sender and stores it in the MAC address table. A switch broadcasts only when it doesn’t know the MAC address of the recipient.
Let’s see this in detail with an example:
When two devices connected in the same LAN communicate with each other, the switch will behave differently for the first-time communication and for the communication that happens afterward.
Let’s consider two scenarios:
1. What happens when A and B communicate for the first time?
Consider Computer A sending data to Computer B. The data packets will be received by the switch, and the switch stores the MAC address of Computer A in its MAC address table. Since A and B are communicating for the first time, the switch doesn’t know the MAC address of B, so it will broadcast the data packets to all the ports. But only Computer B will respond to it. Now the switch captures the MAC address of Computer B and updates its table. This is how the switch works.
2. What happens when A and B communicate the next time?
Now let’s consider B sending data to A. Of course, the switch will receive the data packets, and then it will check its MAC address table to find the address. Will it find the address? Definitely yes, because the switch stored the MAC address of A in its table when A first sent the data to B. So, it won’t broadcast the data again. This is how a switch works in an intelligent way.