Practice
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Frontend UI Machine Coding
Resources
Career Advice and Roadmaps
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Backend Development
Frontend Development
Project Ideas for Software Developers
Core Computer Science
Companies
SDE Jobs & Internships
Interview Questions
Compare Companies
IDE
Online IDE
Collaborative IDE

TCP 3-Way Handshake | Computer Networks

Ujjwal Abhishek
Ujjwal Abhishek

What is TCP 3-Way Handshake?

The TCP 3-Way Handshake is a three-step process that is used to make a secured and reliable connection between a client and server before the actual transmission of data. After these three steps and the establishment of the connection between them, data transfer takes place. 

A secured and reliable connection of TCP is only possible due to this 3-way handshake process.

TCP 3-Way Handshake Process 

The following steps are involved in establishing a connection using the 3-Way Handshake Process.

1. The client starts the process and sets the SYN flag to 1

  • The client sends the message to the server by setting the SYN flag to 1.
  • The message contains some other information like sequence numbers(2000), maximum segment size, window size.
  • A sequence number is a randomly generated 32-bits number.
  • SYN - It stands for synchronization. It sends the message to the server to synchronize with the received sequence number.
  • The window size is used for the flow control. It denotes the capacity of the data that can be received.
  • For example - If the window size is 10000 and the maximum segment size is 1000. Then, the maximum number of data segments that should be transmitted is 10000/1000 = 10.

2. The server replies with (SYN+ACK)

  • After receiving the synchronization request from the client, the server sends the acknowledgment to the client by setting the ACK flag to 1.
  • It sends the Acknowledgment number (ACK) to the client which is just 1 greater than the received sequence number from the client. For example - If the sequence number received from the client is 2000 then the acknowledgment sent by the server will be 2001.
  • It denotes the next sequence expected by the sender.
  • In addition to this, the server also sends a randomly generated sequence number (suppose 4000 ) and sets the SYN flag to 1.
  • The server also sends its window size which is the buffer capacity of the server and maximum segment size to the client for flow control.
  • It is required so that none of the ends need to do the fragmentation of packets.

3. The final acknowledgment from the client (ACK)

  • After receiving the SYN from the server, the client sets the ACK flag to 1.
  • It sends the expected sequence number (2001) by the server which is equal to the Acknowledgment number received from the server.
  • It also sends the Acknowledgment number which is one greater than the sequence number received from the server which denotes the next expected sequence number.

The above three processes are called the TCP 3-Way Handshake. After these three steps, the connection is established between the two. The data can be transmitted between them after the connection establishment.

Ujjwal Abhishek
Ujjwal Abhishek
Ujjwal is final-year CSE Undergraduate, a competitive coder, and a web developer passionate about problem-solving and data structures and algorithms.
SDE Bootcamp - Become a software engineer at a product-based company
Practice Data Structures & Algorithms
Learning Resources
Interview Prep Resources
Blog
  • Career Advice and Roadmaps
  • Data Structures & Algorithms
  • Machine Coding Round (LLD)
  • System Design & Architecture
  • Backend Development
  • Frontend Development
  • Awesome Project Ideas
  • Core Computer Science
Practice Questions
  • Machine Coding (LLD) Questions
  • System Design (HLD) Questions
  • Topic-wise DSA Questions
  • Company-wise DSA Questions
  • DSA Sheets (Curated Lists)
  • JavaScript Interview Questions
  • Frontend UI Machine Coding Questions
Online Compilers (IDE)
  • Online Java Compiler
  • Online C++ Compiler
  • Online C Compiler
  • Online Python Compiler
  • Online JavaScript Compiler
Topic-wise Problems
  • Dynamic Programming Interview Questions
  • Linked List Interview Questions
  • Graph Interview Questions
  • Backtracking Interview Questions
  • Arrays Interview Questions
  • Trees Interview Questions
Company-wise Problems
  • Amazon Interview Questions
  • Microsoft Interview Questions
  • Google Interview Questions
  • Flipkart Interview Questions
  • Adobe Interview Questions
  • Facebook Interview Questions
DSA Sheets (Curated Lists)
  • Top Interview Questions
  • FAANG Interview Questions
  • Most Asked Interview Questions
  • 6 month DSA Practice Sheet
  • 3 month DSA Practice Sheet
  • Last minute DSA Practice Sheet