<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[What is Data Link Layer Switching? A Simple Guide for CSE Students]]></title><description><![CDATA[What is Data Link Layer Switching? A Simple Guide for CSE Students]]></description><link>https://whatisdatalinklayerswitching.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 10:42:03 GMT</lastBuildDate><atom:link href="https://whatisdatalinklayerswitching.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Decoding TCP and UDP Headers, One Bit at a Time]]></title><description><![CDATA[Learn every TCP and UDP header field with simple diagrams: ports, checksum, flags, HLEN, pseudo-header and the 3-way handshake, plus solved GATE problems.]]></description><link>https://whatisdatalinklayerswitching.hashnode.dev/tcp-udp-headers-explained</link><guid isPermaLink="true">https://whatisdatalinklayerswitching.hashnode.dev/tcp-udp-headers-explained</guid><category><![CDATA[networking]]></category><category><![CDATA[TCP]]></category><category><![CDATA[UDP]]></category><category><![CDATA[Begginers]]></category><category><![CDATA[Computer Science]]></category><category><![CDATA[computer networks]]></category><dc:creator><![CDATA[VISHAL M]]></dc:creator><pubDate>Tue, 03 Nov 2026 14:04:18 GMT</pubDate><content:encoded><![CDATA[<p>Open your laptop right now and count what is talking to the internet. A browser with six tabs, WhatsApp Web, Spotify, maybe a game launcher updating in the background. All of these share one Wi-Fi connection and one IP address. So when a packet arrives at your machine, how does your computer know that this particular packet belongs to Spotify and not to Chrome?</p>
<p>The IP layer can't answer that. IP only gets data from one machine to another machine. Getting data to the right program on that machine is the transport layer's job, and it does it with two protocols you will meet in every networks exam: UDP and TCP.</p>
<p>The easiest way to understand how they differ is to look at their headers. A header is the small block of control information stuck to the front of your data. Whatever a protocol can do, it can only do because some field in its header makes it possible. UDP's header is tiny, so UDP does very little. TCP's header is bigger, and every extra field pays for a feature.</p>
<p>This post walks through both headers field by field, then works out two exam-style problems at the end.</p>
<h2>First, ports and sockets</h2>
<p>Think of an apartment building. The building's street address gets the courier to the right building. The flat number gets the parcel to the right family.</p>
<ul>
<li>The IP address is the building address. It identifies the machine.</li>
<li>The port number is the flat number. It identifies the process (program) on that machine.</li>
</ul>
<p>A port number is a 16-bit unsigned integer, so it can be anything from 0 to 65,535. Some ports are well known: 80 for HTTP, 443 for HTTPS, 53 for DNS, 22 for SSH.</p>
<p>Put an IP address and a port together and you get a socket address, written like <code>192.168.1.10:443</code>. A socket address names one exact endpoint on the whole internet: this program, on this machine.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/3b54d3f0-71a2-4c7d-9361-660a812c9cdd.png" alt="" style="display:block;margin:0 auto" />

<p>Notice that a client program, like your browser, does not use port 443 itself. The OS gives it a random temporary port (often above 49152), called an ephemeral port. The server is the side that sits on the well-known port and waits.</p>
<p>Both UDP and TCP start their headers with a source port and a destination port. That is the part they have in common. Everything after that is where they split.</p>
<h2>Where this header lives</h2>
<p>Before reading the fields, it helps to see where the transport header sits. Your message gets wrapped layer by layer, like a letter going into an envelope that then goes into a courier bag.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/16bb16a9-246b-4466-ba0b-0f39c646f807.png" alt="Ethernet header, IP header, TCP or UDP header, application data, FCS" style="display:block;margin:0 auto" />

<p>The application hands its data down. TCP or UDP sticks its header in front and the result is called a segment (TCP) or a user datagram (UDP). IP then adds its own header in front of that, and so on down the stack. The receiver peels the layers off in reverse order. By the time the transport layer sees the packet, the IP header is already gone, which is why the transport header needs its own port numbers.</p>
<h2>The UDP header: 8 bytes and done</h2>
<p>UDP (User Datagram Protocol) is connectionless. It does not set up a connection, does not number its packets, and does not resend anything that gets lost. It hands your data to IP and moves on. People call this "best effort" delivery.</p>
<p>A UDP packet is called a user datagram. Its header is always exactly 8 bytes (64 bits), split into four 16-bit fields:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/8f4453f4-c8d8-444b-93e0-ea8d443b46e0.png" alt="UDP header layout: source port, destination port, length, checksum" style="display:block;margin:0 auto" />

<p>How to read this diagram: each row is 32 bits (4 bytes) wide. The numbers along the top count bit positions. So the first row holds two 16-bit fields side by side.</p>
<h3>Source port (16 bits)</h3>
<p>The port of the program that sent the datagram. If the sender doesn't expect any reply, it is allowed to put 0 here.</p>
<h3>Destination port (16 bits)</h3>
<p>The port of the program that should receive it. A DNS query, for example, goes to port 53.</p>
<h3>Length (16 bits)</h3>
<p>The total size of the user datagram in bytes, header plus data. Since the header alone is 8 bytes, this field can never be less than 8. A datagram with no data at all has Length = 8.</p>
<p>A quick formula worth remembering:</p>
<pre><code class="language-plaintext">Data size = Length - 8
</code></pre>
<h3>Checksum (16 bits)</h3>
<p>Used to detect errors. The checksum is calculated over three things: the UDP header, the data, and a 12-byte pseudo-header borrowed from the IP layer. The pseudo-header contains the source and destination IP addresses, the protocol number, and the UDP length. Including it means a datagram that reached the wrong machine will fail the check, even if its own bytes arrived intact.</p>
<p>In IPv4, the UDP checksum is optional. A sender that skips it fills the field with all zeros. In IPv6 it is mandatory.</p>
<h4>The pseudo-header, field by field</h4>
<p>The pseudo-header trips up a lot of students, so here it is drawn out:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/9d46a948-7f61-417e-a634-7dd14514b9f1.png" alt="IPv4 pseudo-header: source IP, destination IP, zeros, protocol, length" style="display:block;margin:0 auto" />

<table>
<thead>
<tr>
<th>Field</th>
<th>Size</th>
<th>What goes in it</th>
</tr>
</thead>
<tbody><tr>
<td>Source IP address</td>
<td>32 bits</td>
<td>Sender's IP, copied from the IP header</td>
</tr>
<tr>
<td>Destination IP address</td>
<td>32 bits</td>
<td>Receiver's IP, copied from the IP header</td>
</tr>
<tr>
<td>Zeros</td>
<td>8 bits</td>
<td>Padding so the next fields line up</td>
</tr>
<tr>
<td>Protocol</td>
<td>8 bits</td>
<td>17 for UDP, 6 for TCP</td>
</tr>
<tr>
<td>Length</td>
<td>16 bits</td>
<td>The UDP Length field (for TCP, the segment length)</td>
</tr>
</tbody></table>
<p>Add those up: 4 + 4 + 1 + 1 + 2 = 12 bytes. The pseudo-header is never transmitted. The sender builds it in memory just to compute the checksum, and the receiver builds the same thing from the IP header it received. If anything differs, the checksum fails.</p>
<p>The protocol field is a nice detail: it means a UDP datagram can't pass as TCP, because 17 and 6 produce different checksums.</p>
<p>That is the entire UDP header. Two ports, a length, a checksum. No sequence numbers, no acknowledgments, no flags. This is why UDP is fast and why it can lose packets without noticing.</p>
<h2>The TCP header: 20 to 60 bytes of bookkeeping</h2>
<p>TCP (Transmission Control Protocol) makes very different promises. It is connection-oriented, reliable, and treats your data as a continuous stream of bytes. Before sending anything, the two sides set up a connection using the three-way handshake. After that, TCP has to:</p>
<ul>
<li>notice lost data and resend it,</li>
<li>put bytes back in order if they arrive scrambled,</li>
<li>slow down if the receiver can't keep up,</li>
<li>close the connection cleanly at the end.</li>
</ul>
<p>Each of these needs a field in the header. That is why the TCP header is at least 20 bytes and can grow to 60 bytes when options are added.</p>
<p>A TCP packet is called a segment. Here is its header:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/5294b682-b0b3-497c-90e5-306857209bab.png" alt="TCP header layout with all fields and the six control flags" style="display:block;margin:0 auto" />

<p>The first five rows (5 × 4 = 20 bytes) are always there. The Options row is the only part that changes size.</p>
<h3>1. Source and destination ports (16 bits each)</h3>
<p>Same job as in UDP: which program sent this, and which program should get it.</p>
<h3>2. Sequence number (32 bits)</h3>
<p>TCP doesn't number packets. It numbers bytes. Every byte you send gets its own number.</p>
<p>When a connection starts, each side picks a random starting number called the Initial Sequence Number (ISN). The sequence number in a segment's header is the number of the first data byte inside that segment.</p>
<p>An example makes this clear. Say the ISN is 1000, and the sender sends three segments of 100 bytes each:</p>
<table>
<thead>
<tr>
<th>Segment</th>
<th>Bytes carried</th>
<th>Sequence number in header</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>1001 to 1100</td>
<td>1001</td>
</tr>
<tr>
<td>2</td>
<td>1101 to 1200</td>
<td>1101</td>
</tr>
<tr>
<td>3</td>
<td>1201 to 1300</td>
<td>1201</td>
</tr>
</tbody></table>
<p>(The first data byte is ISN + 1 because the SYN at the start of the connection uses up one sequence number.)</p>
<p>If segment 2 arrives before segment 1, the receiver looks at the sequence numbers and puts them back in order.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/2e321bb7-828d-4724-add0-93a494df60d1.png" alt="Three 100-byte segments with sequence numbers 1001, 1101, 1201 and ACK 1301" style="display:block;margin:0 auto" />

<h3>3. Acknowledgment number (32 bits)</h3>
<p>This is how the receiver says what it has received. TCP acknowledgments are cumulative. An acknowledgment number of X means:</p>
<blockquote>
<p>"I've received every byte up to X - 1. Send me byte X next."</p>
</blockquote>
<p>So in the table above, after receiving all three segments correctly, the receiver sends back ACK = 1301.</p>
<p>This field only counts when the ACK flag (below) is set to 1.</p>
<h3>4. Data offset, also called HLEN (4 bits)</h3>
<p>Tells the receiver how long the TCP header is, so it knows where the header ends and the data begins.</p>
<p>The catch, and the thing exams love: the value is counted in 4-byte words, not in bytes.</p>
<pre><code class="language-plaintext">Header length in bytes = HLEN × 4
</code></pre>
<ul>
<li>With no options, the header is 20 bytes, so HLEN = 20 / 4 = 5 (binary <code>0101</code>).</li>
<li>The largest 4-bit value is 15 (binary <code>1111</code>), so the biggest possible header is 15 × 4 = 60 bytes.</li>
<li>That leaves 60 - 20 = 40 bytes as the most space options can ever take.</li>
</ul>
<p>HLEN can never be less than 5. If you see HLEN = 3 in a question, that segment is invalid.</p>
<h3>5. Reserved (6 bits)</h3>
<p>Kept for future use and set to zero. Newer TCP versions use some of these bits for Explicit Congestion Notification (the ECE and CWR flags), but for most university syllabi you can treat this as 6 reserved bits.</p>
<h3>6. Control flags (6 bits)</h3>
<p>Six one-bit switches. Each one is either on (1) or off (0), and together they control the connection.</p>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Name</th>
<th>What it means when set to 1</th>
</tr>
</thead>
<tbody><tr>
<td>URG</td>
<td>Urgent</td>
<td>The Urgent Pointer field is valid</td>
</tr>
<tr>
<td>ACK</td>
<td>Acknowledgment</td>
<td>The Acknowledgment Number field is valid. Almost every segment after the handshake has this set</td>
</tr>
<tr>
<td>PSH</td>
<td>Push</td>
<td>Hand this data to the application now instead of waiting for the buffer to fill</td>
</tr>
<tr>
<td>RST</td>
<td>Reset</td>
<td>Abort the connection right away (invalid connection, refused request, or a crash)</td>
</tr>
<tr>
<td>SYN</td>
<td>Synchronize</td>
<td>Used to set up a connection and exchange starting sequence numbers. Only the first two segments of the three-way handshake have SYN = 1</td>
</tr>
<tr>
<td>FIN</td>
<td>Finish</td>
<td>The sender has no more data and wants to close the connection gracefully</td>
</tr>
</tbody></table>
<p>A trick for remembering the order from left to right: <strong>U</strong>nskilled <strong>A</strong>ttackers <strong>P</strong>ester <strong>R</strong>eal <strong>S</strong>ecurity <strong>F</strong>olks (URG, ACK, PSH, RST, SYN, FIN).</p>
<h4>Watching the flags in action: the three-way handshake</h4>
<p>Flags make more sense once you see them used. This is how a client and server open a TCP connection, and what each header carries:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/59a6396f-e3ab-4ca4-aaad-d914654ce2b3.png" alt="Three-way handshake: SYN, SYN+ACK, ACK with sequence and acknowledgment numbers" style="display:block;margin:0 auto" />

<ol>
<li>The client sends a segment with SYN = 1 and its starting sequence number, say 1000. This segment has no data.</li>
<li>The server replies with SYN = 1 and ACK = 1. It picks its own starting number (5000) and acknowledges the client with ack = 1001.</li>
<li>The client sends ACK = 1 with ack = 5001. The connection is open.</li>
</ol>
<p>Why 1001 and not 1000? A SYN counts as one byte of sequence space even though it carries no data, so the next expected number moves up by one. Closing works the same way with FIN, and a FIN also uses up one sequence number.</p>
<h3>7. Window size (16 bits)</h3>
<p>This is how TCP does flow control. The receiver uses this field to say how many more bytes it currently has room for in its buffer.</p>
<p>Picture pouring water from a jug into a glass. A fast sender is the jug, a slow receiver is the glass. The window field is the receiver telling the sender how much space is left in the glass, so nothing spills over.</p>
<p>Being 16 bits, the window can go up to 65,535 bytes. That turned out to be too small for fast modern networks, so a Window Scale option was added. With scaling, the effective window can reach about 1 GB.</p>
<h3>8. Checksum (16 bits)</h3>
<p>Works the same way as UDP's checksum: it covers the TCP header, the data, and the 12-byte IP pseudo-header. The difference is that in TCP the checksum is always mandatory.</p>
<h3>9. Urgent pointer (16 bits)</h3>
<p>Only used when the URG flag is 1. Its value is added to the sequence number to find where the urgent data inside the segment ends. The classic example is pressing Ctrl + C in a remote terminal session: the interrupt should jump the queue instead of waiting behind everything else.</p>
<h3>10. Options (0 to 40 bytes)</h3>
<p>Extra settings, mostly agreed on during connection setup. Three you should know:</p>
<ul>
<li>MSS (Maximum Segment Size): the largest chunk of data a host is willing to receive in one segment, chosen so IP doesn't have to fragment it.</li>
<li>Window Scaling: lets the window grow past 65,535 bytes, as described above.</li>
<li>SACK (Selective Acknowledgment): lets the receiver say "I got bytes 1 to 100 and 201 to 300, but not 101 to 200," so the sender only resends the missing piece instead of everything after it.</li>
</ul>
<h2>UDP vs TCP side by side</h2>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/ce36b0f8-3eee-4748-a843-6d5f49a27f55.png" alt="UDP header is 2 words, TCP header is 5 to 15 words" style="display:block;margin:0 auto" />

<table>
<thead>
<tr>
<th></th>
<th>UDP</th>
<th>TCP</th>
</tr>
</thead>
<tbody><tr>
<td>Header size</td>
<td>Fixed 8 bytes</td>
<td>20 to 60 bytes</td>
</tr>
<tr>
<td>Connection</td>
<td>None. Just send</td>
<td>Three-way handshake to open, FIN exchange to close</td>
</tr>
<tr>
<td>Ordering</td>
<td>No sequence numbers</td>
<td>Every byte numbered</td>
</tr>
<tr>
<td>Reliability</td>
<td>Best effort. Lost or duplicate packets aren't fixed</td>
<td>Lost data is resent using timers and ACKs</td>
</tr>
<tr>
<td>Flow control</td>
<td>None</td>
<td>Window size field</td>
</tr>
<tr>
<td>Checksum</td>
<td>Optional in IPv4, mandatory in IPv6</td>
<td>Always mandatory</td>
</tr>
<tr>
<td>Typical uses</td>
<td>DNS, VoIP, video streaming, DHCP, online games, QUIC (HTTP/3)</td>
<td>Web browsing (HTTP/HTTPS), file transfer (FTP), SSH, email (SMTP)</td>
</tr>
</tbody></table>
<p>A good way to remember which apps use which: in a video call, a frame that shows up late is useless, so it's better to drop it and move on. That suits UDP. When you download a PDF, one missing byte corrupts the whole file, so you need every byte. That suits TCP.</p>
<h2>Two worked problems</h2>
<p>These are the kinds of questions that show up in GATE and semester exams. Try them before reading the solution.</p>
<h3>Problem 1: decode a UDP header</h3>
<p>A UDP header in hexadecimal is: <code>CB84 000D 001C 001C</code></p>
<p>Find the source port, destination port, total length, and the size of the data.</p>
<p><strong>Solution.</strong> Split the 8 bytes into four 16-bit fields and convert each to decimal.</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Hex</th>
<th>Decimal</th>
</tr>
</thead>
<tbody><tr>
<td>Source port</td>
<td>CB84</td>
<td>52100</td>
</tr>
<tr>
<td>Destination port</td>
<td>000D</td>
<td>13</td>
</tr>
<tr>
<td>Length</td>
<td>001C</td>
<td>28</td>
</tr>
<tr>
<td>Checksum</td>
<td>001C</td>
<td>(not needed)</td>
</tr>
</tbody></table>
<ul>
<li>Source port = 52100</li>
<li>Destination port = 13</li>
<li>Total length = 28 bytes</li>
<li>Data size = 28 - 8 = 20 bytes</li>
</ul>
<p>Bonus inference: the destination port 13 is a well-known port (the daytime service) and the source port is a large random number, so this packet is going from a client to a server.</p>
<h3>Problem 2: decode a TCP header</h3>
<p>A TCP header in hexadecimal is:</p>
<pre><code class="language-plaintext">05320017 00000001 00000000 500207FF 00000000
</code></pre>
<p>Find the ports, sequence number, header length, which flags are set, and the window size.</p>
<p><strong>Solution.</strong> Take it one 32-bit word at a time.</p>
<p>Word 1, <code>0532 0017</code>:</p>
<ul>
<li>Source port = 0x0532 = 1330</li>
<li>Destination port = 0x0017 = 23 (Telnet)</li>
</ul>
<p>Word 2, <code>00000001</code>: sequence number = 1</p>
<p>Word 3, <code>00000000</code>: acknowledgment number = 0</p>
<p>Word 4, <code>5002 07FF</code>: this one needs unpacking into bits.</p>
<pre><code class="language-plaintext">5      0    0    2
0101   0000 0000 0010
HLEN | Reserved (6) | Flags (6)
</code></pre>
<ul>
<li>HLEN = <code>0101</code> = 5, so the header is 5 × 4 = 20 bytes (no options)</li>
<li>The last 6 bits are <code>000010</code>. Reading them as URG ACK PSH RST SYN FIN, only SYN is 1</li>
<li>Window = 0x07FF = 2047 bytes</li>
</ul>
<p>Word 5, <code>0000 0000</code>: checksum and urgent pointer are both 0.</p>
<p>So this is a SYN segment with ACK = 0, which means it is the very first segment of a three-way handshake: a client asking to open a Telnet connection.</p>
<h2>Quick self-check</h2>
<ol>
<li>What is the smallest value the UDP Length field can hold? <em>(8)</em></li>
<li>A TCP header has HLEN = 1010 in binary. How many bytes of options does it carry? <em>(10 × 4 = 40 bytes total, so 40 - 20 = 20 bytes of options)</em></li>
<li>Which header field is how TCP does flow control? <em>(Window size)</em></li>
<li>In IPv4, can a UDP sender skip the checksum? <em>(Yes, by sending all zeros. In IPv6 it can't.)</em></li>
<li>Which segments of the three-way handshake have SYN = 1? <em>(The first two)</em></li>
<li>How big is the IPv4 pseudo-header, and is it sent over the network? <em>(12 bytes. No, it is only used to compute the checksum.)</em></li>
<li>A client's SYN has seq = 3000. What ack number does the server put in its SYN+ACK? <em>(3001)</em></li>
</ol>
<h2>Wrapping up</h2>
<p>When you're stuck on a TCP or UDP question, go back to the headers. UDP has four fields because it only does addressing, length, and an error check, and that is why it is quick and why it can lose data. TCP adds sequence numbers, acknowledgment numbers, flags, and a window, and each of those fields is the reason it can deliver every byte in order over a network that loses and reorders packets. If you can draw both header diagrams from memory and remember that HLEN counts in 4-byte words, you're ready for most exam questions on this topic.</p>
]]></content:encoded></item><item><title><![CDATA[What is Data Link Layer Switching? A Simple Guide for CSE Students]]></title><description><![CDATA[Learn how switches forward frames using MAC addresses: learning, forwarding, filtering, flooding, STP and VLANs, explained simply for CSE students.]]></description><link>https://whatisdatalinklayerswitching.hashnode.dev/what-is-data-link-layer-switching-a-simple-guide-for-cse-students</link><guid isPermaLink="true">https://whatisdatalinklayerswitching.hashnode.dev/what-is-data-link-layer-switching-a-simple-guide-for-cse-students</guid><category><![CDATA[networking]]></category><category><![CDATA[computer networking]]></category><category><![CDATA[Computer Science]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[VISHAL M]]></dc:creator><pubDate>Sun, 01 Nov 2026 19:47:13 GMT</pubDate><content:encoded><![CDATA[<p>Oct 15, 2026 · @VISHAL M</p>
<h2>Introduction</h2>
<p>When you send a file to the computer next to you in the lab, it passes through a small box on the wall or under the desk: a switch. That box decides which cable your data goes out on. It makes that decision thousands of times a second, and it does it using nothing but MAC addresses.</p>
<p>That decision is what we call data link layer switching. Before we get to it, let's place it in the OSI model.</p>
<p>The physical layer (Layer 1) only moves raw bits, 0s and 1s, over a cable or radio. The data link layer (Layer 2) sits just above it. It takes that stream of bits and groups it into chunks called frames. Every frame carries two hardware addresses in its header: the MAC address of the sender (source) and the MAC address of the receiver (destination).</p>
<p>A MAC address is a 48-bit address burned into every network card, usually written like <code>AA:BB:CC:11:22:33</code>. Switching at Layer 2 is all about reading these addresses and moving frames to the right place.</p>
<h2>What is data link layer switching?</h2>
<p>Data link layer switching is the process of forwarding frames from one network segment to another using their destination MAC address. It happens at Layer 2 of the OSI model. The devices that do it are called bridges and switches.</p>
<p>When a frame arrives, the switch reads the destination MAC address and checks its MAC address table. That table tells it which port leads to that address, and the frame goes out of that port only.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/3d342a45-4105-4b31-8b8f-60195affbbbc.webp" alt="" style="display:block;margin:0 auto" />

<p>In this picture the switch already knows that B is on port 2, so A's frame leaves through port 2 and nowhere else.</p>
<p>Here's an analogy that makes it easier to remember. Think of a security guard at the gate of an apartment building with four wings. Parcels arrive all day. On his first day he knows nobody, so for every parcel he walks through all four wings calling out the name. Each time a resident sends a parcel out, though, he writes in his register which wing they came from. After a few days the register is full, and he walks straight to the right wing.</p>
<p>The switch is that guard. The wings are its ports, the parcels are frames, the names are MAC addresses, and the register is the MAC address table.</p>
<h2>Bridge vs switch</h2>
<p>You'll see both words used for the same job, and that's fair, because a switch is a bridge with more ports. The difference is mostly size and speed.</p>
<table>
<thead>
<tr>
<th></th>
<th>Bridge</th>
<th>Switch</th>
</tr>
</thead>
<tbody><tr>
<td>Number of ports</td>
<td>Usually 2 to 4</td>
<td>Many (8, 24, 48 and more)</td>
</tr>
<tr>
<td>How it decides</td>
<td>Often in software</td>
<td>In hardware chips (ASICs)</td>
</tr>
<tr>
<td>Speed</td>
<td>Slower</td>
<td>Much faster</td>
</tr>
<tr>
<td>Where you see it</td>
<td>Older networks, textbooks</td>
<td>Every modern LAN</td>
</tr>
</tbody></table>
<p>The logic is identical. Everything in the rest of this post applies to both, so I'll use "switch" from here on.</p>
<h2>How a switch works</h2>
<p>Every frame that enters a switch goes through the same two steps.</p>
<h3>Step 1: learn from the source</h3>
<p>The switch reads the source MAC address and notes the port the frame arrived on. If host A's frame came in on port 1, the table now says "A is on port 1." Nobody configures this by hand. The switch builds the table from the traffic it sees.</p>
<h3>Step 2: decide using the destination</h3>
<p>Next it looks up the destination MAC address in the table. One of three things happens:</p>
<table>
<thead>
<tr>
<th>Destination is</th>
<th>What the switch does</th>
<th>Name</th>
</tr>
</thead>
<tbody><tr>
<td>Known, on a different port</td>
<td>Sends the frame out of that one port</td>
<td>Forwarding</td>
</tr>
<tr>
<td>Known, on the same port it came in on</td>
<td>Drops the frame</td>
<td>Filtering</td>
</tr>
<tr>
<td>Unknown, or a broadcast (<code>FF:FF:FF:FF:FF:FF</code>)</td>
<td>Sends it out of every port except the one it came in on</td>
<td>Flooding</td>
</tr>
</tbody></table>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/8827db90-b81a-4c46-a428-a5c5e95d5969.webp" alt="" style="display:block;margin:0 auto" />

<p>In all three cases A's frame for B comes in on port 1. Only the result of the table lookup changes what happens next.</p>
<p>Filtering confuses students at first. If the sender and receiver sit on the same port (say, two PCs on a hub that plugs into one switch port), the receiver already got the frame on that segment. Sending it back would waste bandwidth, so the switch throws it away.</p>
<p>Table entries don't last forever. If the switch doesn't hear from a MAC address for a while (300 seconds by default on most switches), it deletes the entry. This is called aging, and it keeps the table correct when a laptop is unplugged or moved.</p>
<h3>A worked example</h3>
<p>Take a switch with three ports. Host A is on port 1, B on port 2 and C on port 3. The table starts empty.</p>
<table>
<thead>
<tr>
<th>Frame</th>
<th>Switch learns</th>
<th>Destination known?</th>
<th>Action</th>
<th>Table afterwards</th>
</tr>
</thead>
<tbody><tr>
<td>A → B</td>
<td>A is on port 1</td>
<td>No</td>
<td>Floods to ports 2 and 3</td>
<td>A:1</td>
</tr>
<tr>
<td>B → A</td>
<td>B is on port 2</td>
<td>Yes, port 1</td>
<td>Forwards to port 1 only</td>
<td>A:1, B:2</td>
</tr>
<tr>
<td>C → B</td>
<td>C is on port 3</td>
<td>Yes, port 2</td>
<td>Forwards to port 2 only</td>
<td>A:1, B:2, C:3</td>
</tr>
<tr>
<td>A → C</td>
<td>Nothing new</td>
<td>Yes, port 3</td>
<td>Forwards to port 3 only</td>
<td>A:1, B:2, C:3</td>
</tr>
</tbody></table>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/917564d5-ad2d-4556-ad64-0f3bf879601d.webp" alt="" style="display:block;margin:0 auto" />

<p>Each panel shows the table right after one frame. The switch only ever adds the sender, which is why a host that never sends anything stays unknown.</p>
<p>Flooding happened only once, for the very first frame. After three frames the switch knows every host and sends each frame to exactly one port. C also received A's first frame during that flood, but its network card saw that the destination wasn't its own MAC address and discarded it.</p>
<p>This is also why bridges are said to ignore the payload. The switch reads only the frame header. Whatever is inside, IPv4, IPv6 or anything else, passes through untouched.</p>
<h2>Types of bridging</h2>
<p>Textbooks usually describe three types.</p>
<ol>
<li><strong>Simple bridging</strong> joins exactly two network segments. The bridge is configured by hand (statically), so an administrator tells it which addresses sit on which side. Picture two small office LANs on the same floor linked by one bridge.</li>
<li><strong>Multi-port bridging</strong> uses one device with many ports, each port leading to its own segment. A modern switch is really a multi-port bridge.</li>
<li><strong>Learning (transparent) bridging</strong> is the type we walked through above. The bridge builds its MAC table by itself from the source addresses of incoming frames. It's called transparent because the hosts never know it's there. They send frames exactly as they would on a plain cable, with no settings to change.</li>
</ol>
<p>Almost every switch you'll touch today is a multi-port, learning bridge.</p>
<h2>Key features</h2>
<h3>MAC address learning</h3>
<p>The switch fills its own MAC table by watching source addresses, as in the worked example. Nobody types entries in, and old entries age out on their own.</p>
<h3>Frame filtering</h3>
<p>A frame goes only where it needs to go. Traffic between two hosts on ports 1 and 2 never appears on port 3, so the rest of the network stays quiet.</p>
<h3>Loop prevention with STP</h3>
<p>Network engineers often connect switches with two cables, so one can take over if the other breaks. That spare cable creates a loop, and loops are a serious problem at Layer 2.</p>
<p>Suppose a broadcast frame leaves switch S1 on cable 1. S2 floods it back to S1 on cable 2. S1 floods it again, and the frame goes round and round. An IP packet in a loop would eventually die, because its TTL (time to live) field drops by one at every router. An Ethernet frame has no TTL field, so it circles forever. Within seconds the links fill up with copies of the same frames. This is called a broadcast storm. The MAC tables also keep flipping, because the same source address keeps arriving from two different ports.</p>
<p>The Spanning Tree Protocol (STP, IEEE 802.1D) fixes this. The switches talk to each other, find the loops and put one port on each redundant path into a blocked state. Only one active path remains between any two switches. If the active cable fails, STP unblocks the spare one.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ad45ebcdc053c98a10e1e0f/17e4d407-16fe-4470-8db0-4619c6ae77d4.webp" alt="" style="display:block;margin:0 auto" />

<p>On the left, both cables carry the same broadcast round and round. On the right, STP has blocked one port, so the loop is broken while the spare cable stays ready.</p>
<h3>VLAN support</h3>
<p>A VLAN (virtual LAN) splits one physical switch into several separate logical networks. You might put the CSE lab on VLAN 10 and the office staff on VLAN 20, all on the same switch. Each VLAN becomes its own broadcast domain, so a broadcast in VLAN 10 never reaches VLAN 20.</p>
<p>Some articles say VLANs join networks into a larger one. It works the other way round. A VLAN divides a network, and traffic between two VLANs needs a router or a Layer 3 switch. Layer 2 switching alone can't move a frame from one VLAN to another.</p>
<h2>Advantages</h2>
<h3>Network segmentation</h3>
<p>This is the advantage examiners ask about most, so it needs two definitions.</p>
<p>A collision domain is the part of a network where two devices sending at the same moment will collide. On an old hub, every port shares one collision domain. A switch gives each port its own collision domain, so a PC on port 1 and a PC on port 5 can send at the same time without trouble.</p>
<p>A broadcast domain is the part of a network that a broadcast frame reaches. A switch floods broadcasts out of every port, so the whole switch is still one broadcast domain. Only a router, or VLANs, can split broadcast domains.</p>
<table>
<thead>
<tr>
<th>Device with 8 ports</th>
<th>Collision domains</th>
<th>Broadcast domains</th>
</tr>
</thead>
<tbody><tr>
<td>Hub</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>Switch</td>
<td>8</td>
<td>1</td>
</tr>
<tr>
<td>Router (8 interfaces)</td>
<td>8</td>
<td>8</td>
</tr>
</tbody></table>
<p>An easy line to remember: switches break up collision domains, routers break up broadcast domains.</p>
<h3>Transparent operation</h3>
<p>Plugging in a switch requires no change on any computer. Hosts keep sending frames the way they always did, and the switch works out the rest.</p>
<h3>Protocol independence</h3>
<p>The switch reads only the Layer 2 header. It forwards an IPv4 packet, an IPv6 packet or anything else inside the frame the same way.</p>
<h3>Scalability</h3>
<p>When a lab grows, you connect another switch to an existing one. The new switch learns its own MAC table, STP keeps the paths loop-free, and the network grows without being redesigned.</p>
<h2>Conclusion</h2>
<p>Data link layer switching moves frames between ports using MAC addresses. A switch learns where each host is from the source address, then forwards, filters or floods each frame based on the destination address. STP stops loops from turning into broadcast storms, and VLANs let one switch act as several separate networks.</p>
<p>If you keep one sentence from this post, make it this: source to learn, destination to decide.</p>
<h2>Quick quiz</h2>
<p>Try these before you look at the answers.</p>
<ol>
<li>Which address does a switch use to build its MAC table?</li>
<li>A frame arrives with a destination MAC that isn't in the table. What does the switch do?</li>
<li>A 24-port switch with no VLANs has how many collision domains and how many broadcast domains?</li>
<li>Why can a frame loop forever between switches when an IP packet can't?</li>
<li>The table says host D is on port 3, and a frame for D arrives on port 3. What happens?</li>
</ol>
<h3>Answers</h3>
<ol>
<li>The source MAC address. The destination is used only to decide where the frame goes.</li>
<li>It floods the frame out of every port except the one it came in on.</li>
<li>24 collision domains and 1 broadcast domain.</li>
<li>Ethernet frames have no TTL field, so nothing removes them. STP prevents the loop in the first place.</li>
<li>The switch filters (drops) the frame, because D is on the same segment and has already received it.</li>
</ol>
]]></content:encoded></item></channel></rss>