The Wayback Machine - https://web.archive.org/web/20240821142010/https://www.geeksforgeeks.org/tcp-3-way-handshake-process/
Open In App

TCP 3-Way Handshake Process

Last Updated : 23 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The TCP 3-Way Handshake is a fundamental process that establishes a reliable connection between two devices over a TCP/IP network. It involves three steps: SYN (Synchronize), SYN-ACK (Synchronize-Acknowledge), and ACK (Acknowledge). During the handshake, the client and server exchange initial sequence numbers and confirm the connection establishment. In this article, we will discuss the TCP 3-Way Handshake Process.

What is the TCP 3-Way Handshake?

The TCP 3-Way Handshake is a fundamental process used in the Transmission Control Protocol (TCP) to establish a reliable connection between a client and a server before data transmission begins. This handshake ensures that both parties are synchronized and ready for communication.

TCP Segment Structure

A TCP segment consists of data bytes to be sent and a header that is added to the data by TCP as shown: 

TCP Segment

The header of a TCP segment can range from 20-60 bytes. 40 bytes are for options. If there are no options, a header is 20 bytes else it can be of upmost 60 bytes. Header fields: 

  • Source Port Address: A 16-bit field that holds the port address of the application that is sending the data segment. 
  • Destination Port Address: A 16-bit field that holds the port address of the application in the host that is receiving the data segment. 
  • Sequence Number: A 32-bit field that holds the sequence number, i.e, the byte number of the first byte that is sent in that particular segment. It is used to reassemble the message at the receiving end of the segments that are received out of order. 
  • Acknowledgement Number: A 32-bit field that holds the acknowledgement number, i.e, the byte number that the receiver expects to receive next. It is an acknowledgement for the previous bytes being received successfully. 
  • Header Length (HLEN): This is a 4-bit field that indicates the length of the TCP header by a number of 4-byte words in the header, i.e if the header is 20 bytes(min length of TCP header), then this field will hold 5 (because 5 x 4 = 20) and the maximum length: 60 bytes, then it’ll hold the value 15(because 15 x 4 = 60). Hence, the value of this field is always between 5 and 15. 
  • Control flags: These are 6 1-bit control bits that control connection establishment, connection termination, connection abortion, flow control, mode of transfer etc. Their function is: 
    • URG: Urgent pointer is valid
    • ACK: Acknowledgement number is valid( used in case of cumulative acknowledgement)
    • PSH: Request for push
    • RST: Reset the connection
    • SYN: Synchronize sequence numbers
    • FIN: Terminate the connection
  • Window size: This field tells the window size of the sending TCP in bytes. 
  • Checksum: This field holds the checksum for error control. It is mandatory in TCP as opposed to UDP. 
  • Urgent pointer: This field (valid only if the URG control flag is set) is used to point to data that is urgently required that needs to reach the receiving process at the earliest. The value of this field is added to the sequence number to get the byte number of the last urgent byte. 

TCP 3-way Handshake Process

The process of communication between devices over the internet happens according to the current TCP/IP suite model(stripped-out version of OSI reference model). The Application layer is a top pile of a stack of TCP/IP models from where network-referenced applications like web browsers on the client side establish a connection with the server. From the application layer, the information is transferred to the transport layer where our topic comes into the picture. The two important protocols of this layer are – TCP, and UDP(User Datagram Protocol) out of which TCP is prevalent(since it provides reliability for the connection established). However, you can find an application of UDP in querying the DNS server to get the binary equivalent of the Domain Name used for the website. 

TCP 3 Way Handshaking

TCP provides reliable communication with something called Positive Acknowledgement with Re-transmission(PAR). The Protocol Data Unit(PDU) of the transport layer is called a segment. Now a device using PAR resend the data unit until it receives an acknowledgement. If the data unit received at the receiver’s end is damaged(It checks the data with checksum functionality of the transport layer that is used for Error Detection), the receiver discards the segment. So the sender has to resend the data unit for which positive acknowledgement is not received. You can realize from the above mechanism that three segments are exchanged between sender(client) and receiver(server) for a reliable TCP connection to get established. Let us delve into how this mechanism works

TCP 3 Way Handshake

  • Step 1 (SYN): In the first step, the client wants to establish a connection with a server, so it sends a segment with SYN(Synchronize Sequence Number) which informs the server that the client is likely to start communication and with what sequence number it starts segments with
  • Step 2 (SYN + ACK): Server responds to the client request with SYN-ACK signal bits set. Acknowledgement(ACK) signifies the response of the segment it received and SYN signifies with what sequence number it is likely to start the segments with
  • Step 3 (ACK): In the final part client acknowledges the response of the server and they both establish a reliable connection with which they will start the actual data transfer

Question For Practice

Question: Consider a TCP client and a TCP server running on two different machines. After completing the data transfer, the TCP client calls close to terminate the connection and a FIN segment is sent to the TCP server. Server-side TCP responds by sending an ACK which is received by the client-side TCP. As per the TCP connection state diagram(RFC 793), in which state does the client-side TCP connection wait for the FIN from the server-side TCP? [GATE-CS-2017 (Set 1)]
(A) LAST-ACK 
(B) TIME-WAIT 
(C) FIN-WAIT-1 
(D) FIN-WAIT-2 

Explanation : (D) For detail solution visit the article. GATE PYQs

Conclusion

The TCP 3-Way Handshake is a critical mechanism for establishing a secure connection between a client and a server over a TCP/IP network. It consists of three important steps: the client initiates the connection by sending an SYN packet, the server responds with a SYN-ACK message to acknowledge the client’s request and synchronize sequence numbers, and the client sends an ACK packet to complete the connection. This handshake ensures that both sides are in sync and prepared for dependable data transmission, making it an essential mechanism for stable and secure communication in TCP/IP networks.

Frequently Asked Questions on TCP 3-Way Handshake Process – FAQs

What is the purpose of the SYN flag in the TCP three-way handshake?

The SYN (Synchronize Sequence Number) flag is used in the initial step of the handshake. It informs the server that the client wants to establish a connection and specifies the sequence number for subsequent segments.

Why is a three-way handshake necessary in TCP/IP networks?

The three-way handshake ensures reliable communication by establishing a connection between the client and server. It confirms that both parties are ready for data transfer and synchronizes their sequence numbers.

How does the TCP three-way handshake affect network security?

The handshake helps prevent unauthorized connections. Without it, malicious actors could potentially establish connections without proper synchronization



Previous Article
Next Article

Similar Reads

Why TCP Connect Termination Need 4-Way-Handshake?
The modern developments in everyday life, in terms of technology and the internet, are only made possible with the help of the TCP/IP suite. TCP is been used for communication among devices on the network. It stands for Transmission Control Protocol. It can work with any type of network, whether personal networks or the internet. For instance, it c
8 min read
Impact of Three-way Handshake and Slow Start Algorithm
Internet became something without which our lives are incomplete. Every day each internet user makes 100s of queries on the internet, be it a simple google search or visiting any website and no one likes the delay in the response. In this article, we will discuss time delay that affects internet speed. A three-way handshake was introduced in the in
8 min read
TCP with explicit link failure notification (TCP-ELFN)
TCP with Explicit Link Failure Notification (TCP-ELFN) is an end to end approach used in TCP Ad Hoc wireless networks to improve the performance by decoupling the path break information from congestion information. TCP-ELFN does not depend upon any routing protocols as it requires explicitly only the link failure notification when there is a path f
2 min read
TCP Tahoe and TCP Reno
TCP is known as a connection-oriented protocol, which ensures reliability and is also responsible for congestion control mechanisms in the network. TCP Tahoe and TCP Reno are two techniques of TCP congestion control, these are used when the sender receives three duplicate acknowledgments. TCP Tahoe where Tahoe is a lake in the USA. This particular
4 min read
TCP Fast Open and TCP/IP Acceleration
The TCP Fast Open (TFO) and TCP/IP Acceleration are techniques used to improve the performance and efficiency of TCP connections in computer networks. These techniques aim to reduce the latency and improve the throughput of the TCP connections, especially for short-lived connections and web browsing scenarios. TCP Fast Open (TFO): The TCP Fast Open
3 min read
Challenge Handshake Authentication Protocol (CHAP)
Challenge Handshake Authentication Protocol (CHAP) is a Point-to-point protocol (PPP) authentication protocol developed by IETF (Internet Engineering Task Force). It is used at the initial startup of the link. Also, it performs periodic checkups to check if the router is still communicating with the same host. Features : It uses 3-way handshaking p
5 min read
Transport Layer Security (TLS) Handshake
TLS is a data privacy and security protocol implemented for secure communication over internet. It usually encrypts communication between server and clients. TLS is a successor to Secure Socket Layer (SSL) protocol. SSL v3.0 and TLS v1.0 were very similar but it was replaced with TLS. You can also refer to Transport Layer Security (TLS). A Transpor
2 min read
How to Fix the SSL/TLS Handshake Failed Error?
Secure Sockets Layer (SSL): It is an internet security protocol based on encryption. It was developed in the year 1996 by Netscape to ensure privacy, authentication, and data integrity. It is the predecessor to TLS encryption. It provides a secure channel between two devices or machines communicating over the Internet or even an internal network. S
3 min read
What is SSL/TLS Handshake?
The network is important for office, home, and business networks. The problem is at the utmost places wireless communication is used or we can say the wireless network is used which is effortlessly hackable and the router can be freely exploited if not secured rightly. So there's a need for security in the network. To fulfill this need we can use s
6 min read
Basic concept of TCP-Vegas
TCP Reno and TCP Tahoe models can determine the congestion in the network only when there some packet loss occurred in the system. So in these models, we have compensated for the packet to sense the congestion in the network. In these models when packet loss occurs the window size is decreased and the system enters the congestion avoidance phase. W
3 min read
TCP Server-Client implementation in C
Prerequisites - Socket Programming in C/C++, TCP and UDP server using select, UDP Server-Client implementation in C If we are creating a connection between client and server using TCP then it has a few functionalities like, TCP is suited for applications that require high reliability, and transmission time is relatively less critical. It is used by
4 min read
TCP Connection Establishment
Prerequisite – TCP 3-Way Handshake Process TCP is a connection-oriented protocol and every connection-oriented protocol needs to establish a connection in order to reserve resources at both the communicating ends. Connection Establishment - 1. Sender starts the process with the following: Sequence number (Seq=521): contains the random initial seque
3 min read
TCP flags
In TCP connection, flags are used to indicate a particular state of connection or to provide some additional useful information like troubleshooting purposes or to handle a control of a particular connection. Most commonly used flags are "SYN", "ACK" and "FIN". Each flag corresponds to 1 bit information. Types of Flags: Synchronization (SYN) - It i
4 min read
What is TCP Window Scaling?
In the TCP header, the window size field is of size 16 bits. Using this field TCP users (client or server) can advertise a maximum of 216 = 65536 bytes or 64 KiB as its buffer size to its other end-user. But modern endpoint devices (e.g., phones, tabs, PCs, etc) have much more memory available in their buffers. This 16-bit field was enough during t
5 min read
Wrap Around Concept and TCP Sequence Number
Prerequisite - TCP | Services and Segment structure Transmission Control Protocol (TCP) is one of the most important protocols of the internet protocol. It provides full transport-layer service to applications and generates a virtual circuit between sender and receiver that is active for the duration of the transmission. Its segment consists of a T
6 min read
Devices used in each layer of TCP/IP model
Prerequisite - TCP/IP Model, Network Devices 1. Physical Layer - Physical layer of TCP/IP model is responsible for physical connectivity of two devices. Some of the devices used in Physical layers are, Hubs: Hubs are devices commonly used to connect segments of a LAN. It contains multiple input/output ports. when signal is at any input port, this s
4 min read
TCP and UDP in Transport Layer
Layer 3 or the Network layer uses IP or Internet Protocol which being a connection less protocol treats every packet individually and separately leading to lack of reliability during a transmission. For example, when data is sent from one host to another, each packet may take a different path even if it belongs to the same session. This means the p
4 min read
OSI, TCP/IP and Hybrid Models
OSI Model is developed by International Organization for Standardization or ISO, the Open Systems Interconnection model or OSI model is a critical building block in networking. OSI Model helps in troubleshooting and understanding networks because of the layered approach that it follows. It consists of seven layers in which each layer has its functi
4 min read
Traditional TCP
Transmission Control Protocol (TCP) is the transport layer protocol that serves as an interface between client and server. The TCP/IP protocol is used to transfer the data packets between transport layer and network layer. Transport protocol is mainly designed for fixed end systems and fixed, wired networks. In simple terms, the traditional TCP is
4 min read
Calculation of TCP Checksum
In this article, we will learn a good concept of how the TCP/UDP checksum is calculated. When we receive data from the application it is broken into smaller data parts as the whole data from the application cannot be sent through the network to the receiver host. The protocol we use in OSI in the Transport layer is TCP. So, after breaking the data
4 min read
Difference between TCP and RTP
1. TCP : TCP is a connection oriented protocol in which the communicating devices establish a connection before transmitting data and close the connection after transmitting the data. 2. RTP : Real-Time Transport Protocol (RTP) is a network protocol which is used for delivering audio and video over networks. RTP is basically used in communication a
1 min read
TCP/IP in Computer Networking
Introduction : TCP/IP (Transmission Control Protocol/Internet Protocol) is a suite of communication protocols that define the standards for transmitting data over computer networks, including the internet. The TCP/IP protocol is the foundation of the internet and enables devices to communicate with each other using a common language. The TCP/IP pro
8 min read
Various TCP and UDP ports
Transportation layer conventions utilize the idea of ports and multiplexing/demultiplexing to convey information to individual services listening on network nodes. These ports are spoken to by a solitary 16-bit number, implying that they can constitute a range of numbers 0-65535. This range has been separated by the IANA (Internet Assigned Numbers
4 min read
Difference between SCTP and TCP
1. Stream Control Transmission Protocol (SCTP) : SCTP is connection- oriented protocol in computer networks which provides full-duplex association i.e., transmitting multiple streams of data between two end points at the same time that have established connection in network. 2. Transmission Control Protocol (TCP) : TCP is connection oriented reliab
1 min read
How to calculate Maximum Segment Size in TCP?
Maximum Segment Size refers to size of the largest segment that local host accepts within a single packet. It denotes largest amount of data that host can accept in single TCP segment. For establishing the TCP connection, both sender and receiver indicates Maximum Segment Size they can accept. While transmitting the packets over TCP connection send
3 min read
Vegas A ( Modified TCP-Vegas )
Vegas A is the modification of TCP Vegas. The A in Vegas A stands for adaptive.TCP Vegas has a fixed value of the constant alpha and beta. So it does not do better when it is in connection with TCP Reno. Therefore, in Vegas A these constants are not fixed but change according to the throughput and the extra data in the queue. In the starting, the v
4 min read
Construct a simple HTTP request on TCP protocol
HTTP Request : HTTP messages are how data is exchanged between a server and a client. In this, there are two types of messages where one is HTTP client request and the second is the response from the server.Messages in textual form and it is encoded in ASCII form, and span over multiple lines. And messages were openly sent across the connection in
3 min read
Similarities between TCP/IP model and OSI model
Pre-Requisite: Layers of OSI Model, TCP/IP Model OSI Model or Open Systems Interconnection is an architecture of 7 layers in which each layer has its work to perform whereas TCP/IP is a concise version of the OSI Model. TCP/IP Model consists of 4 layers rather than the 7 layers of the OSI Model. There are so many similarities between the TCP/IP mod
5 min read
Fast Recovery Technique For Loss Recovery in TCP
When the RTO timer expires but an ACK is not received, the sender confirms that the packet is lost due to congestion at intermediary devices. Now sender has to tackle this congestion state carefully. Fast Recovery is the packet loss recovery technique. Recovery means becoming inactive and not transmitting any new packet for some time. When there is
4 min read
Snooping TCP
In this article, we will discuss the overview of Snooping TCP, and its working, and then will discuss the advantages and disadvantages of Snooping TCP. Let's discuss it one by one. Overview :Snooping TCP is one of the classical TCP improvement approaches. This approach is designed to solve the end-to-end semantics loss in I-TCP. The basic concept i
3 min read
Article Tags :
three90RightbarBannerImg