TCP Handshakes and 3-Way Handshakes

Ayush AgarwalAyush Agarwal
4 min read

The TCP Three-Way Handshake: What It Is and Why It’s Important

Have you ever wondered how your computer establishes a reliable connection with a website? Much like a formal business meeting begins with introductions and handshakes, computers on the internet follow a similar protocol called the TCP 3-way handshake. This fundamental process ensures secure and reliable communication between devices across the vast digital landscape.

The Transmission Control Protocol (TCP) is a cornerstone of internet communication, providing reliable, ordered, and error-checked delivery of data between applications. Before any data exchange occurs, TCP employs a three-way handshake to establish a connection between a client and a server. This handshake synchronizes both parties, ensuring they are ready to communicate and agree upon initial sequence numbers, which are crucial for tracking the data segments transmitted.

Steps Involved in the Three-Way Handshake:

1. SYN (Synchronize): The client initiates the connection by sending a TCP segment with the SYN flag set. This segment includes an initial sequence number (ISN), a randomly chosen value that marks the beginning of the data flow from the client.

2. SYN-ACK (Synchronize-Acknowledge): Upon receiving the SYN segment, the server responds with a segment that has both SYN and ACK flags set. This response acknowledges the client’s SYN and provides the server’s own ISN, indicating readiness to establish a connection.

3. ACK (Acknowledge): The client acknowledges the server’s SYN-ACK by sending a final segment with the ACK flag set, confirming the establishment of the connection.

This process ensures that both the client and server are synchronized and agree upon the initial parameters for data transmission, laying the groundwork for reliable communication.


How the Internet Says ‘Hello’: A Visual Guide to TCP Handshakes

To better understand this process, consider this real-world analogy:

Imagine two business partners meeting for the first time:

  • Client: "Hello, I'm interested in doing business with you." (SYN)

  • Server: "Hello, yes, I received your greeting and I'm also interested in doing business." (SYN-ACK)

  • Client: "Excellent, let's begin our discussion." (ACK)

This exchange ensures both parties are present, attentive, and ready to communicate effectively.

Example

Imagine you’re initiating a conversation with a friend; you greet them, they acknowledge, and the dialogue begins. Similarly, in the digital realm, devices establish communication through a process known as the TCP three-way handshake. This fundamental mechanism ensures reliable data transmission across networks, forming the backbone of our internet interactions.


Reliable Connections in TCP: How Sequence Numbers and ACKs Work

Once the connection is established, TCP uses sequence numbers and acknowledgments (ACKs) to manage data transmission.

Sequence Numbers: Each byte of data is assigned a unique sequence number. This numbering allows the receiver to reorder segments if they arrive out of sequence and to detect any missing data.

Acknowledgments (ACKs): The receiver sends ACKs to inform the sender of the next expected sequence number. This mechanism confirms receipt of data and indicates readiness to receive more.

Example

Suppose a client sends 500 bytes of data starting with sequence number 1001:

Client: Sends data with sequence numbers 1001 to 1500.

Server: Receives the data and responds with an ACK indicating that it expects the next byte to be 1501.

If any data is lost during transmission, the absence of an expected ACK prompts the sender to retransmit the missing segments, ensuring data integrity.


Conclusion

The TCP three-way handshake is the backbone of modern networking, ensuring that every piece of data sent over the internet is received completely, accurately, and in the correct order. Without it, the internet would be unreliable, with lost messages, disorganized files, and broken communication. By protecting against data loss, maintaining sequencing, and ensuring acknowledgment-based reliability, TCP continues to be one of the most trusted and widely used protocols in networking today.

The TCP three-way handshake is a fundamental process that establishes reliable connections over the internet. By synchronizing sequence numbers and exchanging acknowledgments, TCP ensures that data is transmitted accurately and in order, providing a dependable foundation for network communication.

10
Subscribe to my newsletter

Read articles from Ayush Agarwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ayush Agarwal
Ayush Agarwal