<?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[TCP Working]]></title><description><![CDATA[TCP Working]]></description><link>https://intro-to-tcp.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 20 Sep 2026 08:04:57 GMT</lastBuildDate><atom:link href="https://intro-to-tcp.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[TCP Working: 3-Way Handshake & Reliable Communication]]></title><description><![CDATA[Imagine you want to make an announcement in your school . You start shouting your place where everyone is busy with their own work ,so nobody listens to you . It feels like there is no decorum in the class , no rules and no discipline in the class.
I...]]></description><link>https://intro-to-tcp.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://intro-to-tcp.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[TCP]]></category><category><![CDATA[TCP Handshake]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[HARSH YADAV]]></dc:creator><pubDate>Fri, 30 Jan 2026 07:19:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769616109297/ff94d820-95d2-4302-9c8b-d8737cf052f4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine you want to make an announcement in your school . You start shouting your place where everyone is busy with their own work ,so nobody listens to you . It feels like there is no decorum in the class , no rules and no discipline in the class.</p>
<p>It is similar sending data (the announcement ) without any rules and regulations (class decorum).<br />This is where a protocol comes in - A set of rules that defines what to communicate , when to communicate and how to communicate , ensuring the message reaches the right place in the right way.</p>
<p>In this blog , we will deep dive into TCP(Transmission Control Program Protocol) and uncover how it brings order , reliability and discipline to data communication - opening the black box behind one the most important protocols of the networking.</p>
<h2 id="heading-what-is-tcp">What is TCP ?</h2>
<p>TCP is like a teacher distributing the papers to <strong>student by student</strong> (data sent in the order) in the exam room .<br />Each student confirms (Acknowledgement) , if a paper is missing , teacher re-gives the paper to that student (re-transmission).<br />Teacher waits if students aren’t ready (flow control) and silence in the class ensure no confusion(congestion control).</p>
<p>Teacher ensures that paper is delivered to each student , in order and reliably , not fast and Chaotic .</p>
<p>TCP is a protocol that allows devices to communicate reliably over the network. It ensures that reaches the data at the destination in the right order and in the right way .<br />It works at Transport Layer (Layer - 4 ) in the OSI model and is essential part of the TCP/IP suite.</p>
<h2 id="heading-tcp-working">TCP Working</h2>
<p>TCP works step by steps:-</p>
<ol>
<li><strong>Connection is created</strong></li>
</ol>
<ul>
<li>TCP makes sure before sending the data , both sides are ready . It uses 3-way handshake for the connection establishment.</li>
</ul>
<h3 id="heading-3-way-handshake">3-way Handshake</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769753489040/b0547867-345f-42ca-899b-d17b1f9a42dc.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>It is calling someone : ring → Hello → okay , talk</p>
</li>
<li><p>In similar way, TCP uses syn , syn-ack and ack segment to establish connection.</p>
</li>
</ul>
<ol>
<li><p><strong>Synchronize(SYN) :-</strong></p>
<p> Client send the syn segment to receiver for requesting the connection .</p>
</li>
<li><p>Synchronize-Acknowledge (SYN-ACK) :-</p>
<p> Server responds with syn-ack segment , acknowledging the request and agreeing to the connection.</p>
</li>
<li><p>Acknowledgement :-</p>
<p> Client again sends an ack segment to confirm the connection is established.</p>
</li>
<li><p><strong>Segmenting:-</strong></p>
<p> When an application sends the data , it is broken into smaller chunks called segment . Each segment has a header containing the information like sequence numbers , ports and flags</p>
</li>
<li><p><strong>Data transmission:-</strong></p>
<p> Segments are transmitted over the network . They may arrive <strong>out-of-order</strong> or different paths.</p>
</li>
<li><p><strong>Acknowledgement &amp; Reliability</strong></p>
<p> Receiver sends an ack for successfully received segments . If an ack is not received within a time-limit , segment is re-transmitted.</p>
</li>
<li><p><strong>Flow Control</strong></p>
<p> TCP uses window size to control the amount of the data , ensuring the receiver is not overloaded.</p>
</li>
<li><p><strong>Congestion Control</strong></p>
<p> TCP adjusts its sending rate based on network to avoid traffic congestion</p>
</li>
<li><p><strong>Connection Termination</strong></p>
<p> After data is transmitted , connection is terminated using <strong>FIN</strong> and <strong>ACK</strong> messages.</p>
</li>
</ol>
<h2 id="heading-sequence-number-and-acknowledgement-in-tcp">Sequence number and Acknowledgement in TCP</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769754831144/b52fdef9-8471-4146-93d6-32e26c88a623.png" alt class="image--center mx-auto" /></p>
<p><strong>Sequence number</strong></p>
<p>Sequence number tells from which the DATA byte starts . TCP counts bytes , not packets.</p>
<p><em>From the diagram:</em></p>
<p>Clients sends SYN , SEQ = 100 which means data will start from 100.</p>
<p>After the handshake, first data:</p>
<ul>
<li><p><strong>DATA (100 bytes), SEQ = 101.</strong></p>
<p>  Next data:</p>
</li>
<li><p><strong>DATA (200 bytes), SEQ = 201</strong></p>
<p>  SEQ always increases by <strong>number of bytes sent</strong>.</p>
</li>
</ul>
<p><strong>Acknowledgement Number</strong></p>
<p>It tells the byte number expected. It means ”I received everything before this byte”.</p>
<p><em>From the diagram:</em></p>
<p>ACK = 401 means I have received bytes 101 to 400. Sends byte 401 next .</p>
<p>After client sends <strong>50</strong> bytes (SEQ = 401)</p>
<p>Server replies :</p>
<ul>
<li>ACK = 451 means Data till byte <strong>450</strong> received.</li>
</ul>
<h2 id="heading-packet-loss-and-re-transmission-flow">Packet loss and re-transmission Flow</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769756188421/99dadc39-099b-409b-85ad-42e27e3848e0.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Data Transmission</strong><br /> The sender transmits data segments, each with a <strong>sequence number</strong> that identifies the starting byte of the data.</p>
</li>
<li><p><strong>Packet Loss Occurs</strong><br /> Due to network issues, a data packet may get <strong>lost</strong> before reaching the receiver.</p>
</li>
<li><p><strong>No Acknowledgement Received</strong><br /> Since the receiver does not get the packet, it <strong>cannot send an ACK</strong> for that data.</p>
</li>
<li><p><strong>Sender Waits for Timeout</strong><br /> The sender waits for a specific time called the <strong>retransmission timeout (RTO)</strong>.</p>
</li>
<li><p><strong>Loss Detection</strong><br /> If no ACK is received before the timeout expires, the sender <strong>assumes the packet is lost</strong>.</p>
</li>
<li><p><strong>Retransmission</strong><br /> The sender <strong>retransmits the same packet</strong> using the <strong>same sequence number</strong>.</p>
</li>
<li><p><strong>Acknowledgement After Retransmission</strong><br /> Once the receiver gets the retransmitted packet, it sends an <strong>ACK indicating the next expected byte</strong>.</p>
</li>
<li><p><strong>Normal Transmission Continues</strong><br /> Data transfer continues smoothly after successful acknowledgement.</p>
</li>
</ol>
<h2 id="heading-connection-termination">Connection Termination</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769756718642/8d4fcff2-8ba7-41cc-ae37-7830ffe077ab.png" alt class="image--center mx-auto" /></p>
<p>TCP uses <strong>4-way Handshake</strong> for the connection termination.</p>
<ul>
<li><p><strong>1. FIN:</strong><br />  The <strong>client sends a FIN packet to the server</strong>, indicating that it has finished sending data and wants to close its side of the connection.</p>
<p>  <strong>2. ACK:</strong><br />  The <strong>server replies with an ACK</strong>, confirming that it has received the client’s close request.</p>
<p>  At this point, the <strong>client cannot send data</strong>, but the <strong>server can still send data if required</strong>.</p>
<p>  <strong>3. FIN:</strong><br />  When the server finishes sending its data, it <strong>sends a FIN packet to the client</strong>, indicating that it also wants to close its side of the connection.</p>
<p>  <strong>4. ACK:</strong><br />  The <strong>client sends an ACK</strong> to the server, confirming that it has received the server’s FIN request.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>