<?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[The handshake that runs the internet]]></title><description><![CDATA[Learn how TCP works under the hood, including the 3-way handshake, data transfer, reliability mechanisms, congestion control, and connection termination explained in a simple and visual way.]]></description><link>https://tcp-101-handshake.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6950d2465402e13d3348b495/531e93e7-f37a-4485-8898-54698c2f4667.png</url><title>The handshake that runs the internet</title><link>https://tcp-101-handshake.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 15:36:43 GMT</lastBuildDate><atom:link href="https://tcp-101-handshake.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How TCP Establishes a Connection Before a Single Byte Is Sent
]]></title><description><![CDATA[Table of content

Introduction to TCP

What is TCP?

Why TCP is needed in networking



Problems TCP is Designed to Solve

Packet loss

Out-of-order delivery

Data duplication

Congestion issues



Un]]></description><link>https://tcp-101-handshake.hashnode.dev/how-tcp-establishes-a-connection-before-a-single-byte-is-sent</link><guid isPermaLink="true">https://tcp-101-handshake.hashnode.dev/how-tcp-establishes-a-connection-before-a-single-byte-is-sent</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[TCP]]></category><category><![CDATA[tcp/ip-model]]></category><category><![CDATA[three way handshake]]></category><category><![CDATA[technology]]></category><category><![CDATA[tech ]]></category><dc:creator><![CDATA[Anshul Tripathi]]></dc:creator><pubDate>Fri, 08 May 2026 07:53:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950d2465402e13d3348b495/c472f1c5-c9c6-4ad8-947f-cb9e54073195.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Table of content</strong></p>
<ol>
<li><p><strong>Introduction to TCP</strong></p>
<ul>
<li><p>What is TCP?</p>
</li>
<li><p>Why TCP is needed in networking</p>
</li>
</ul>
</li>
<li><p><strong>Problems TCP is Designed to Solve</strong></p>
<ul>
<li><p>Packet loss</p>
</li>
<li><p>Out-of-order delivery</p>
</li>
<li><p>Data duplication</p>
</li>
<li><p>Congestion issues</p>
</li>
</ul>
</li>
<li><p><strong>Understanding the TCP 3-Way Handshake</strong></p>
<ul>
<li><p>What is connection establishment?</p>
</li>
<li><p>Why handshake is required</p>
</li>
</ul>
</li>
<li><p><strong>How Data Transfer Works in TCP</strong></p>
<ul>
<li><p>Segmentation of data</p>
</li>
<li><p>Sequence numbers</p>
</li>
<li><p>Acknowledgment system</p>
</li>
</ul>
</li>
<li><p><strong>How TCP Ensures Reliability, Order, and Correctness</strong></p>
<ul>
<li><p>Error detection (checksum)</p>
</li>
<li><p>Flow control</p>
</li>
<li><p>Congestion control</p>
</li>
<li><p>Retransmission mechanism</p>
</li>
</ul>
</li>
<li><p><strong>How a TCP Connection is Closed</strong></p>
<ul>
<li><p>4-Way Handshake explanation</p>
</li>
<li><p>FIN and ACK process</p>
</li>
<li><p>TIME_WAIT state</p>
</li>
</ul>
</li>
<li><p><strong>Conclusion</strong></p>
<ul>
<li><p>Key takeaways</p>
</li>
<li><p>When to use TCP</p>
</li>
</ul>
</li>
</ol>
<hr />
<h2>1 . Introduction</h2>
<p>Just imagine what will happen if the data is send without any rules and regulation, would we able to get the data in the same order as the server has sent to client and would we be able to understand someones data if any packet is lost and how we are going to understand that there is a loss of packet . That's where the TCP comes in picture , in this blog we are going to understand about how TCP works under the hood and how TCP helps to establish a reliable connection between the computers and how TCP is responsible for congestion control .</p>
<h3>All about TCP</h3>
<p>TCP stands for Transmission Control Protocol which is responsible for the reliable data sharing . It acts like the courier service which ensures that the data reaches between the computer is intact , in order and without any error. It shares the data by making a <mark class="bg-yellow-200 dark:bg-yellow-500/30">three-way handshak</mark>e first and then it starts to share the data without any error .</p>
<h3>Why TCP is needed in networking</h3>
<p>The need of TCP in the networking is to ensure reliable, ordered and error checked delivery of data between the application . It acts as a foundational connection- oriented protocol establishing a connection by a three - way handshake and automatically retransmitting the packet to ensure the data - integrate .</p>
<hr />
<h2>2 . Problem TCP is designed to solve</h2>
<p>The Problem that TCP was designed to solve was the unreliable data delivery over packet switched network . It ensures reliable , ordered and error checked delivery of a stream of byte between the application , addressing packet loss , duplication , disordering and network congestion .</p>
<p>The key problems TCP was designed to solve are :-</p>
<ul>
<li><p><strong>Reliable Data Transfer</strong> : - TCP uses acknowledgment (ack) and retransmission to ensure that the data packets have delivered to the destination.</p>
</li>
<li><p><strong>Out of order delivery</strong> : Packets may take different paths but TCP uses sequence number to reassemble the data in order at the receiver .</p>
</li>
<li><p><strong>Data corruption</strong> : TCP uses checksums to detect corrupted data and request retransmission .</p>
</li>
<li><p><strong>Network Congestion</strong> : TCP dynamically adjusts transmission rates (using slow start and congestion avoidance) to prevent overloading the network.</p>
</li>
<li><p><strong>Flow control</strong> : Prevents the fast sender from overwhelming the slower receiver by managing the receiver buffering space .</p>
</li>
<li><p><strong>Process- to - Process communication</strong> : Uses port numbers to direct data to the correct application , allowing multiple applications to use the network simultaneously.</p>
</li>
</ul>
<p>Without TCP , applications would have to manage these data integrity and flow control issues themselves , making network applications much harder to develop.</p>
<hr />
<h2>3. Understand the TCP three-way handshake</h2>
<p>TCP is a connection based protocol , it ensures the reliability using the Positive Acknowledgment with the Retransmission . It synchronises sequence numbers, exchanges window sizes, and verifies both parties are ready to communicate, ensuring reliable, ordered data delivery.</p>
<p>The three - way handshake Process looks something like this :-</p>
<ol>
<li><p><strong>SYN ( Synchronise )</strong> : The client initiates the connection by sending a TCP Segment with the SYN flag which is set to <code>1</code> to the server , along with a random initial sequence number ( ISN ) for eg - x .</p>
</li>
<li><p><strong>SYN - ACK (Synchronise - Acknowledgment)</strong> : The server server receives the SYN , and it sets the SYN and ACK flag to <code>1</code> and then it responses with its own random sequence number ( eg - y ) then the Acknowledgment number is set to the clients ISN + 1 i.e ( x + 1 ) .</p>
</li>
<li><p><strong>ACK Acknowledgment</strong> : The client acknowledges the server's response by sending an ACK segment with the ACK flag set to <code>1</code> . The sequence number is x + 1 and the acknowledgment number is y + 1 and once the server receives this the connection established successfully .</p>
</li>
</ol>
<h3>Why the handshake is required</h3>
<p>The handshake is required to ensure that the sender and receiver's have established the connection properly without any issues . Without the three-way handshake there could be the problem of the data loss and no congestion control over the packets .</p>
<img src="https://cdn.hashnode.com/uploads/covers/6950d2465402e13d3348b495/d12e447b-ea74-4f2e-93ec-54d5e01e155f.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>4 . How data is transfer work in TCP</h2>
<p>We all know that the connection is established through a three -way handshake . TCP creates a session that ensures that both the parties are ready</p>
<ul>
<li><p><strong>SYN</strong> : The client sends the synchronise segment to the server.</p>
</li>
<li><p><strong>SYN - ACK</strong> : The server acknowledge the request with a synchronise acknowledgment .</p>
</li>
<li><p><strong>ACK</strong> : The client acknowledges the serves response .</p>
</li>
</ul>
<p>Now lets understand the Data Transmission processes :</p>
<ol>
<li><p><strong>Segmentation</strong> : Large data streams are divided into small chunks called segments .</p>
</li>
<li><p><strong>Sequencing</strong> : Each segment is assigned a sequence number so that the receiver can reorder them if they have reached out of order ,</p>
</li>
<li><p><strong>Full-duplex communication</strong> : Both the client and server can send and receive the data simultaneously .</p>
</li>
<li><p><strong>Error checking</strong> : The receiving TCP calculates the checksum for each segment , if the checksum does not matches then that packet is discarded .</p>
</li>
</ol>
<hr />
<h3>5 . <strong>How TCP Ensures Reliability, Order, and Correctness</strong></h3>
<p>The TCP ensures reliable , ordered and correctness by creating a connection - oriented session , using sequence number of ordering and employing acknowledgment for error detection and retransmission . It maintains data integrity via checksum and manages flow control flow to prevent receiver overloading .</p>
<p>Now lets understand the core mechanism of the reliable communication :</p>
<ul>
<li><p><strong>Connection establishment ( handshake )</strong> : TCP establishes a session between sender and receiver , ensuring both are ready to before data transfer begins</p>
</li>
<li><p><strong>Sequence Number ordering</strong> : Each bytes is assigned a sequence number, allowing the use to reassemble the data packets if they reaches out of the order .</p>
</li>
<li><p><strong>Acknowledgments (Reliability):</strong> The receiver sends an ACK to confirm successful receipt of data; if a packet is lost, the sender retransmits it based on missing ACKs (Timeout/Retransmission).</p>
</li>
<li><p><strong>Checksums (Correctness):</strong> Every segment includes a checksum. The receiver calculates its own checksum and compares it with the sender’s to detect corrupted packets, which are then discarded.</p>
</li>
<li><p><strong>Flow Control (Efficiency):</strong> Using a "sliding window" mechanism, the receiver informs the sender of available buffer space, preventing the sender from overwhelming the receiver.</p>
</li>
<li><p><strong>Congestion Control:</strong> TCP monitors network conditions and reduces data rates if it detects congestion to prevent packet loss.</p>
</li>
</ul>
<p>This mechanism ensures that the data which is shared arrives to the user in correct order and without any data loss or data damage .</p>
<hr />
<h2>6 . How TCP connection is closed</h2>
<p>The TCP closing connection or <mark class="bg-yellow-200 dark:bg-yellow-500/30">teardown</mark> is a reliable <mark class="bg-yellow-200 dark:bg-yellow-500/30">four - way - handshake </mark> initiated by the client . It allows both the sides to terminate the connection equally and independently ensuring that all data is transferred properly and there is no pending data in between of the network . This process is crucial for data integrity , as it prevent the loss of data in either directions .</p>
<p>Lets understand the key steps of the connection termination :-</p>
<ol>
<li><p><strong>FIN ( Finish ) client ⤑ server</strong> : When the client has no more data to send and its sends a FIN segment to the server , transitioning to the <code>FIN - WAIT -1</code> state .</p>
</li>
<li><p><strong>ACK ( Acknowledgment ) ( Server ⤑ Client )</strong> : The server receives the FIN and sends an ACK , acknowledging the close request . The server enters the <code>CLOSE - WAIT</code> state while the client moves to the <code>FIN - WAIT -2</code></p>
</li>
<li><p><strong>FIN ( SERVER → CLIENT )</strong> : Once the server is done sending the data it sends its own <code>FIN</code> segment to the client and then the servers enters the <code>LAST -ACK</code> stage .</p>
</li>
<li><p><strong>ACK ( Client - Server )</strong> : The client receives the <code>FIN</code> and then sends the <code>ACK</code> , transitioning to the <code>TIME-WAIT</code> state, which allows it to handle any delayed packets. The server receives this final ACK and closes the connection (<code>CLOSED</code> state).</p>
</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/6950d2465402e13d3348b495/7fe65aef-4f52-4a79-a6de-044f27abe20f.jpg" alt="" style="display:block;margin:0 auto" />

<p>After waiting a set period (typically /(2x times) /Maximum Segment Lifetime - MSL) in the <code>TIME-WAIT</code> state to ensure the final ACK was received, the client also closes the connection.</p>
<hr />
<h2>7 . Conclusion</h2>
<p>In this blog we have explored all about how TCP works under the hood and how TCP makes a reliable and ordered connection without any data loss. We have also tried understand how the 3 - way handshake and how TCP transfers data using segmentation, sequence numbers, and acknowledgments, while ensuring reliability through retransmissions, flow control, congestion control, and checksum-based error detection</p>
<p>We have understand the how the four - way handshake works and how the <code>Time- wait</code> is important for preventing the delayed packets from causing the issues .</p>
<p>If you stayed till last thank you for your patience and thank you for reading out the blog . Please share this blog with your friends and family and also pls give the feedback and like the blog .</p>
<h3>Thank you 😀</h3>
]]></content:encoded></item></channel></rss>