Skip to main content

Network Switch

In Turkish
Ağ Anahtarı
Updated 3 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/network-switch

In short

A network switch is a device that connects devices on the same local network and forwards each frame only to the port where its destination MAC address lives.

What is a network switch?

A network switch is a box with many Ethernet ports that connects computers, servers, printers, Wi-Fi access points, and other devices into one local network. When a frame, the unit of data on an Ethernet link, arrives on one port, the switch sends it out only on the port where the destination device is connected. Switches mostly work at the data link layer, layer 2 of the OSI model, and make their decisions using MAC addresses.

A switch learns where devices are by watching traffic. Every time a frame arrives, it records the frame's source MAC address and the port it came in on in its MAC address table. To forward a frame, it looks up the destination MAC address: if the address is known, the frame goes out of that one port, and if it isn't, or the frame is a broadcast, the switch floods it out of every other port and learns the missing location from the reply. Managed switches add features such as VLANs, which split one physical switch into several isolated virtual networks, and port mirroring, which copies traffic to a monitoring port.

Think of a switch as the internal mail room of an office: it knows which desk each person sits at and delivers each note directly, instead of reading it aloud to the whole floor. Switches are the backbone of office networks and data centers, where each rack of servers connects to a top-of-rack switch that links to larger switches above it. The few Ethernet ports on the back of a home router are a small built-in switch.

A switch is often confused with a router and with a hub. A hub is an older, simpler device that repeats every frame to every port, which wastes bandwidth and lets every device see everyone's traffic, while a switch sends each frame only where it needs to go. A router connects different networks and forwards packets by IP address, whereas a switch connects devices within one network by MAC address. So-called layer 3 switches blur the line by adding routing between VLANs, but the core job of a switch is still local delivery.

Key takeaways

  • A network switch connects devices within a single local network.
  • It forwards frames by destination MAC address, at layer 2 of the OSI model.
  • It learns which device is on which port by recording source MAC addresses in a MAC address table.
  • Frames to unknown destinations, and broadcasts, are flooded to every other port.
  • A hub repeats traffic to every port and a router connects different networks; a switch does neither.

Example

Simulating how a switch learns and forwardspython
# MAC addresses are shortened here to keep the example readable
mac_table = {}  # MAC address -> port number

def receive(frame, in_port, all_ports=(1, 2, 3, 4)):
    mac_table[frame["src"]] = in_port  # learn which port the sender is on
    out = mac_table.get(frame["dst"])
    if out is None or frame["dst"] == "ff:ff":
        return [p for p in all_ports if p != in_port]  # unknown or broadcast: flood
    return [out]  # known destination: forward out of one port only

print(receive({"src": "aa:aa", "dst": "bb:bb"}, in_port=1))  # [2, 3, 4]
print(receive({"src": "bb:bb", "dst": "aa:aa"}, in_port=2))  # [1]
print(receive({"src": "aa:aa", "dst": "bb:bb"}, in_port=1))  # [2]

Readers ask

What is the difference between a switch and a router?

A switch connects devices within one local network and forwards frames by MAC address. A router connects different networks, such as a home network and the internet, and forwards packets by IP address.

What is the difference between a switch and a hub?

A hub copies every incoming frame to all of its ports, so all devices share the bandwidth and see each other's traffic. A switch learns where each device is and sends frames only to the right port, which is faster and more private, and hubs are now essentially obsolete.

What is a managed switch?

A managed switch can be configured over the network and supports features such as VLANs, traffic prioritization, port monitoring, and port security. An unmanaged switch works out of the box with no settings, which is fine for small home and office networks.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings