<?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: 3-Way Handshake]]></title><description><![CDATA[TCP Working: 3-Way Handshake]]></description><link>https://tcp-3-way-handshake-guide.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 09:37:40 GMT</lastBuildDate><atom:link href="https://tcp-3-way-handshake-guide.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[What happens if data is sent without rules?
Imagine you are sending an important message to a friend, but:

messages may arrive late

messages may arrive out of order

some messages may never arrive

you don’t know if the other person received them

...]]></description><link>https://tcp-3-way-handshake-guide.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://tcp-3-way-handshake-guide.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[#chai code #cohort2026]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[TCP Handshake]]></category><category><![CDATA[TCP]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Mohammed Mohsin]]></dc:creator><pubDate>Sat, 31 Jan 2026 07:37:37 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-what-happens-if-data-is-sent-without-rules">What happens if data is sent without rules?</h3>
<p>Imagine you are sending an important message to a friend, but:</p>
<ul>
<li><p>messages may arrive late</p>
</li>
<li><p>messages may arrive out of order</p>
</li>
<li><p>some messages may never arrive</p>
</li>
<li><p>you don’t know if the other person received them</p>
</li>
</ul>
<p>That’s exactly what would happen on the internet <strong>without rules</strong>.</p>
<p>Computers need a proper way to:</p>
<ul>
<li><p>start a conversation</p>
</li>
<li><p>send data safely</p>
</li>
<li><p>know if data arrived correctly</p>
</li>
<li><p>end the conversation cleanly</p>
</li>
</ul>
<p>This is where <strong>TCP</strong> comes in.</p>
<hr />
<h2 id="heading-what-is-tcp-and-why-it-is-needed">What is TCP and why it is needed?</h2>
<p><strong>TCP</strong> stands for <strong>Transmission Control Protocol</strong>.</p>
<p>TCP is a set of rules that makes sure:</p>
<ul>
<li><p>data reaches the correct destination</p>
</li>
<li><p>data arrives in the correct order</p>
</li>
<li><p>missing data is resent</p>
</li>
<li><p>both sides agree before talking and before stopping</p>
</li>
</ul>
<p>In short:</p>
<blockquote>
<p>TCP makes internet communication <strong>reliable</strong>.</p>
</blockquote>
<p>Most important applications use TCP:</p>
<ul>
<li><p>websites (HTTP / HTTPS)</p>
</li>
<li><p>emails</p>
</li>
<li><p>file transfers</p>
</li>
<li><p>APIs</p>
</li>
</ul>
<hr />
<h2 id="heading-problems-tcp-is-designed-to-solve">Problems TCP is designed to solve</h2>
<p>TCP exists because the internet itself is <strong>unreliable</strong>.</p>
<p>TCP solves problems like:</p>
<ul>
<li><p>data getting lost</p>
</li>
<li><p>data arriving out of order</p>
</li>
<li><p>duplicate data</p>
</li>
<li><p>sending data too fast for the receiver</p>
</li>
</ul>
<p>Instead of assuming everything works, TCP <strong>checks and confirms</strong> at every step.</p>
<hr />
<h2 id="heading-what-is-the-tcp-3-way-handshake">What is the TCP 3-Way Handshake?</h2>
<p>Before any data is sent, TCP first <strong>establishes a connection</strong>.</p>
<p>This process is called the <strong>3-Way Handshake</strong>.</p>
<p>Think of it like starting a phone call:</p>
<ol>
<li><p>“Can I talk to you?”</p>
</li>
<li><p>“Yes, I’m ready.”</p>
</li>
<li><p>“Great, let’s start.”</p>
</li>
</ol>
<p>Only after this do both sides start sending data.</p>
<p><img src="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-establishing-connection-6a724e77ba96e241.jpg" alt="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-establishing-connection-6a724e77ba96e241.jpg" /></p>
<p><img src="https://www.flamingbytes.com/images/tcp-handshake-1.png" alt="https://www.flamingbytes.com/images/tcp-handshake-1.png" /></p>
<p><img src="https://substackcdn.com/image/fetch/%24s_%211nC8%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png" alt="https://substackcdn.com/image/fetch/%24s_%211nC8%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png" /></p>
<hr />
<h2 id="heading-step-by-step-syn-syn-ack-ack">Step-by-step: SYN, SYN-ACK, ACK</h2>
<h3 id="heading-step-1-syn-client-server">Step 1: SYN (Client → Server)</h3>
<p>The client sends a <strong>SYN</strong> message.</p>
<p>Meaning:</p>
<blockquote>
<p>“I want to start a connection.”</p>
</blockquote>
<p>It also sends a <strong>sequence number</strong>, which is like:</p>
<blockquote>
<p>“This is my starting point.”</p>
</blockquote>
<hr />
<h3 id="heading-step-2-syn-ack-server-client">Step 2: SYN-ACK (Server → Client)</h3>
<p>The server replies with <strong>SYN-ACK</strong>.</p>
<p>Meaning:</p>
<blockquote>
<p>“I got your request, and I’m ready too.”</p>
</blockquote>
<p>Here the server:</p>
<ul>
<li><p>acknowledges the client’s sequence number</p>
</li>
<li><p>sends its own sequence number</p>
</li>
</ul>
<hr />
<h3 id="heading-step-3-ack-client-server">Step 3: ACK (Client → Server)</h3>
<p>The client sends <strong>ACK</strong>.</p>
<p>Meaning:</p>
<blockquote>
<p>“I received your response. Let’s start talking.”</p>
</blockquote>
<p>Now the connection is <strong>established</strong>.</p>
<p>Both sides are synchronized and ready to send data.</p>
<hr />
<h2 id="heading-how-data-transfer-works-in-tcp">How data transfer works in TCP</h2>
<p>Once the connection is open, data flows both ways.</p>
<p>But TCP doesn’t send data blindly.</p>
<p>It:</p>
<ul>
<li><p>breaks data into smaller chunks</p>
</li>
<li><p>numbers each chunk</p>
</li>
<li><p>waits for confirmation</p>
</li>
</ul>
<p><img src="https://static.wixstatic.com/media/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg/v1/fill/w_566%2Ch_480%2Cal_c%2Clg_1%2Cq_80/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg" alt="https://static.wixstatic.com/media/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg/v1/fill/w_566%2Ch_480%2Cal_c%2Clg_1%2Cq_80/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg" /></p>
<p><img src="https://www.researchgate.net/publication/331853081/figure/fig6/AS%3A738951123968001%401553191085267/A-simplified-Seq-ACK-numbers-timeline-showing-a-case-of-TCP-retransmission-timeout.png" alt="https://www.researchgate.net/publication/331853081/figure/fig6/AS%3A738951123968001%401553191085267/A-simplified-Seq-ACK-numbers-timeline-showing-a-case-of-TCP-retransmission-timeout.png" /></p>
<p><img src="https://images.openai.com/static-rsc-3/1G-VIZDe46FpuqDYB1S2CqT6uKKiHgsSRxDJSI-wFNy8L0j8HJN1mUoQgvIo_uRKbRAvosL5A9S_AFjU7RDXzk02T-tZMVIrA4HQsb6SXDY?purpose=fullsize" alt="https://images.openai.com/static-rsc-3/1G-VIZDe46FpuqDYB1S2CqT6uKKiHgsSRxDJSI-wFNy8L0j8HJN1mUoQgvIo_uRKbRAvosL5A9S_AFjU7RDXzk02T-tZMVIrA4HQsb6SXDY?purpose=fullsize" /></p>
<p>Each chunk has:</p>
<ul>
<li><p>a <strong>sequence number</strong></p>
</li>
<li><p>an <strong>ACK number</strong> from the receiver</p>
</li>
</ul>
<p>This helps TCP track everything accurately.</p>
<hr />
<h2 id="heading-how-tcp-ensures-reliability-order-and-correctness">How TCP ensures reliability, order, and correctness</h2>
<h3 id="heading-1-sequence-numbers">1. Sequence Numbers</h3>
<p>Every piece of data is numbered.<br />This ensures:</p>
<ul>
<li><p>correct order</p>
</li>
<li><p>no missing pieces</p>
</li>
</ul>
<hr />
<h3 id="heading-2-acknowledgements-ack">2. Acknowledgements (ACK)</h3>
<p>The receiver confirms:</p>
<blockquote>
<p>“I got data up to this point.”</p>
</blockquote>
<p>If the sender doesn’t get an ACK, it assumes something went wrong.</p>
<hr />
<h3 id="heading-3-retransmission">3. Retransmission</h3>
<p>If data is lost:</p>
<ul>
<li><p>sender resends only the missing part</p>
</li>
<li><p>not the whole data again</p>
</li>
</ul>
<p><img src="https://www.researchgate.net/publication/382092781/figure/fig1/AS%3A11431281259508197%401720533616113/TCP-packet-loss-detection-and-retransmission-triggered-by-a-timeout-or-by-three-duplicate.ppm" alt="https://www.researchgate.net/publication/382092781/figure/fig1/AS%3A11431281259508197%401720533616113/TCP-packet-loss-detection-and-retransmission-triggered-by-a-timeout-or-by-three-duplicate.ppm" /></p>
<p><img src="https://www.cs.csustan.edu/~john/Classes/Previous_Semesters/CS3000_Communication_Networks/2008_01_Winter/Notes/Gifs2/f25_2c.gif" alt="https://www.cs.csustan.edu/~john/Classes/Previous_Semesters/CS3000_Communication_Networks/2008_01_Winter/Notes/Gifs2/f25_2c.gif" /></p>
<p><img src="https://learningnetwork.cisco.com/sfc/servlet.shepherd/version/renditionDownload?contentId=05T3i00000ACNNu&amp;operationContext=CHATTER&amp;page=0&amp;rendition=THUMB720BY480&amp;versionId=0683i000001roT7" alt="https://learningnetwork.cisco.com/sfc/servlet.shepherd/version/renditionDownload?contentId=05T3i00000ACNNu&amp;operationContext=CHATTER&amp;page=0&amp;rendition=THUMB720BY480&amp;versionId=0683i000001roT7" /></p>
<hr />
<h3 id="heading-4-flow-control">4. Flow Control</h3>
<p>TCP avoids overwhelming the receiver by:</p>
<ul>
<li><p>sending data at a safe speed</p>
</li>
<li><p>adjusting based on receiver’s capacity</p>
</li>
</ul>
<p>This keeps communication smooth.</p>
<hr />
<h2 id="heading-how-a-tcp-connection-is-closed">How a TCP connection is closed</h2>
<p>Just like starting a connection, closing it also follows rules.</p>
<p>TCP uses <strong>FIN</strong> and <strong>ACK</strong>.</p>
<h3 id="heading-step-1-fin">Step 1: FIN</h3>
<p>One side says:</p>
<blockquote>
<p>“I’m done sending data.”</p>
</blockquote>
<hr />
<h3 id="heading-step-2-ack">Step 2: ACK</h3>
<p>The other side replies:</p>
<blockquote>
<p>“I received your finish request.”</p>
</blockquote>
<hr />
<h3 id="heading-step-3-amp-4-repeat-from-other-side">Step 3 &amp; 4: Repeat from other side</h3>
<p>The second side also sends <strong>FIN</strong>, and the first side replies with <strong>ACK</strong>.</p>
<p>Now the connection is <strong>fully closed</strong>.</p>
<p><img src="https://images.openai.com/static-rsc-1/y6MM7b1qn0yE9aTpXoGuRZVTMNJy40Uj8YSkZCzLX4DCrHauBq29EcHm_Yrtv9CgBRjyNnwiyyCO6PtL-Ph-XolHrLoY7nJMcsZrL4wfa_wQxm3PsA4Gzp3SQ_WVVLWPrQiDcXhy-sK5pdIgJTU6Dw" alt="https://www.tcpipguide.com/free/diagrams/tcpclose.png" /></p>
<p><img src="https://www.excentis.com/web/image/122886-2cd58847/tekening_website_blog.webp?access_token=ecea94ef-81de-4cf4-93a0-58e365abdb55" alt="https://www.excentis.com/web/image/122886-2cd58847/tekening_website_blog.webp?access_token=ecea94ef-81de-4cf4-93a0-58e365abdb55" /></p>
<p><img src="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.png" alt="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.png" /></p>
<hr />
<h2 id="heading-tcp-connection-lifecycle">TCP connection lifecycle</h2>
<p><img src="https://www.ibm.com/support/pages/system/files/inline-images/Flow%20chart%20TCP%20connection_0.jpg" alt="https://www.ibm.com/support/pages/system/files/inline-images/Flow%20chart%20TCP%20connection_0.jpg" /></p>
<p><img src="https://intronetworks.cs.luc.edu/current2/html/_images/tcp_state_diagram_fixed2_scaled.svg" alt="https://intronetworks.cs.luc.edu/current2/html/_images/tcp_state_diagram_fixed2_scaled.svg" /></p>
<p><img src="https://totozhang.github.io/2016-01-23-tcp-connection-status-transit/TCPState2.png" alt="https://totozhang.github.io/2016-01-23-tcp-connection-status-transit/TCPState2.png" /></p>
<ol>
<li><p>Connection established (3-way handshake)</p>
</li>
<li><p>Data transferred reliably</p>
</li>
<li><p>Connection closed cleanly</p>
</li>
</ol>
]]></content:encoded></item></channel></rss>