Learn to initiate talk: TCP and Three-way Handshake


TCP is the transport layer protocol before learning about this protocol, we should first understand "What problem does TCP solve?" and "What is the job of the transport layer?"
1) What is the job of the transport layer?
The transport layer (Layer 4 of the OSI model) is responsible for end-to-end communication between applications running on different devices.
Its primary jobs include:
Segmentation and Reassembly: Breaks large messages from the application layer into smaller segments for transmission and reassembles these segments into the original message at the receiver’s end.
Flow Control: Prevents the sender from overwhelming the receiver by adjusting the rate of data transmission.
Error Detection and Correction: Includes checksums to detect corrupted data and triggers retransmissions if errors are found.
Connection Management: Establishes, maintains, and terminates sessions between communicating devices.
QoS (Quality of Service): While not as explicit in TCP, the transport layer is responsible for ensuring the required quality of service in terms of speed, reliability, and latency.
Multiplexing and Demultiplexing: Allows multiple applications to share the same network connection. Ports are used to identify specific processes or applications (e.g., port 80 for HTTP).
2) What problem does TCP solve?
TCP (Transmission Control Protocol) solves multiple problems associated with reliable communication over an unreliable and unpredictable network, like the Internet.
It ensures reliable delivery of Data through retransmissions, acknowledgements, and error-checking mechanisms.
It implements sequence numbers to track data. If a packet isn’t acknowledged, TCP retransmits it.
Uses sequence numbers to reorder out-of-sequence packets and discard duplicates.
Heavy traffic in networks causes packet loss and performance degradation. So it manages congestion control with algorithms like Slow Start and Congestion Avoidance to adapt the sending rate.
A fast sender can overwhelm a slow receiver, causing buffer overflow. So it implements flow control using a sliding window mechanism to match the sender’s speed to the receiver's capacity.
It establishes a connection-oriented session with the three-way handshake and manages orderly connection termination to ensure synchronized data exchange.
TCP essentially transforms an unreliable packet-switching network into a reliable, error-free channel suitable for applications like web browsing, file transfers, and emails.
Now, we have a good understanding of the Transport layer and TCP.
Let's dive deeper into TCP by learning about the Three-Way Handshake between sender and receiver.
3) What is the TCP Three-Way Handshake?
The TCP three-way handshake is the process that establishes a reliable connection between a client and a server.
It ensures both parties are ready to exchange data and sets the stage for error-free communication by synchronizing their sequence numbers and acknowledging each other’s presence.
Think of it as a polite greeting:
The client says, “Hello, I’d like to talk 😊.”
The server responds, “Hello, I got you. Go ahead 😉.”
The client confirms, “Great, let’s start! 😄”
This exchange ensures both sides are synchronized and ready to communicate.
While this analogy is great for understanding TCP Three-Way Handshake, let's understand some technical terms like sequence number and acknowledgement, etc.
Sequence number: Each Byte in the stream that TCP sends is numbered. The sequence number wraps bake to 0 after (2^32 )- 1.
Acknowledgment number: If the receiver of the segment has successfully received byte number
x
from the other party, it definesx + 1
as the acknowledgement number.
Three-way Handshake Process
SYN: Synchronization Request
The client initiates the handshake by sending a SYN (synchronize) packet to the server. This packet contains a randomly chosen Initial Sequence Number (ISN), which is a unique number identifying the first byte of data the client plans to send.
This informs the server that the client wants to make a connection.
For example, client sends SYNc (ISN) = 500, where c = client
SYN-ACK: Synchronization and Acknowledgment
The server, upon receiving the SYN from the client, acknowledges it by sending back a SYN-ACK packet. This packet serves two purposes:
SYN: The server sends its own Initial Sequence Number (Y).
ACK: The server acknowledges the client’s SYN by setting the acknowledgement number to X + 1.
In our example, server sends:
SYNs (ISN) = 4500
ACKs = 500 + 1 = 501 here s = server
ACK: Acknowledgment
Finally, the client responds with an ACKc packet, confirming the server’s SYNs and completing the handshake. The acknowledgement number is set to Y + 1, indicating that the client has received the server’s sequence number. client sends: ACKc = 4500 + 1 = 4501
At this point, the connection is established and data transfer can begin.
Conclusion
The TCP three-way handshake is a simple yet powerful mechanism that forms the foundation of reliable internet communication. Ensuring both parties are synchronized and ready to exchange data, it provides the backbone for countless applications we use daily, from browsing the web to streaming videos.
Understanding this process not only deepens your knowledge of networking but also highlights the intricate engineering that keeps the internet running smoothly.
If you are interested in learning more about TCP then I would recommend you to check out TCP Headers.
Let me know if you liked this blog or any suggestions 😊.
Thank you.
Subscribe to my newsletter
Read articles from Jasmin Patel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Jasmin Patel
Jasmin Patel
Aspiring AI/ML enthusiast and self-taught software development student passionate about creating and simplifying complex technologies. With strong skills in Python, Django, ML, Javascript, DBMS, and Tailwind CSS, I’m driven by a curiosity for fields like AI, astrophysics, and backend web development. My approach to learning is all about making things simple and practical, allowing me to grasp and apply new concepts quickly. I’m focused on advancing my expertise in AI and backend development, intending to master Python and JavaScript. I’m excited to connect with others in tech, especially those interested in AI, machine learning, and software development, and I’m always open to exploring new opportunities and challenges.