Computer Science Logo
TCP Handshakes explained in detail

TCP Handshakes | 3-Way and 4-Way TCP handshake

TCP Handshakes are to establish or terminate the connection between sender and receiver. You can read more in detail about TCP here. A three-Way handshake is to establish the connection with the server. 4-Way TCP handshake is to finish the connection and to make sure the transmission is successful. Handshakes use flags to communicate with the receiver.

TCP/IP establishes the connection before starting sending the data. Once the data is successful, then it also terminates the connection to avoid using the bandwidth uselessly. To establish the connection TCP uses the “Three-Way Handshake” method. To terminate the connection it uses “4-Way Handshake”. Below is the description of how “TCP Handshakes” works.

TCP Handshakes

3-Way Handshake

TCP is a secure way of sending data. It makes sure that the transmission is successful. In TCP Data transmission it requires an “Acknowledgment” for each packet it sends. Before it starts sending the data first it establishes a connection with the receiver to prevent loss of data.

To establish the connection first it asks the receiver if it wants to receive the data or not? If the receiver is able to receive the data it acknowledges the sender that “Okay I am ready to receive the data”. The sender sends another message to the receiver “Okay the next packet will be the original data”. Since everyone knows that computers cannot communicate in simple words like mentioned above.

The language they speak and understand in this case is “Flags”. You can consider these flags as traffic lights. In Three-Way Handshake “SYN”, “SYN-ACK”, and “ACK” flags are used to communicate between sender and receiver. The sender first sends the “SYN” flag to the receiver which means that the sender wants to send something. if the sender receives back an “SYN-ACK” flag that means that receiver is ready to receive the data. Then the sender sends the “ACK” flag to tell the receiver that the next packet will be the data.

When the sender finishes the data transmission, it terminates the connection with the server using a Four-Way Handshake

4-Way TCP Handshake

4-Way Handshake is the sign that everything went smoothly during the transmission of the data and the data has been reached its destination successfully. A four-Way handshake terminates the connection between sender and receiver so that someone else can use the bandwidth for their data transmission. If the sender does not finish the connection then the receiver will expect other packets from the sender and if does not receive then it may think that some error might have occurred during the transmission.

At the end of the data transmission, the sender sends a “FIN” flag which tells the receiver that I have finished sending the data you may now close the connection. the receiver sends the “ACK” flag which means that “Okay I have received all of your data along with the FIN flag”. the receiver sends “FIN” flag to the sender which means that “Okay then if no data is left let’s close the connection”. The sender sends “ACK” flag to know the receiver that “I have received your FIN flag as well and now I am closing the connection from my side”. When the receiver receives the last “ACK” flag it immediately closes the connection with the sender.

After the Four-Way Handshake, if the sender wants to send other data to the same receiver, it must repeat the process from a 3-Way handshake.

You can read more about flags used in TCP in detail here

3-Way & 4-Way Handshake Diagram

3-way Handshake and 4-way Handshake diagram
3-way Handshake and 4-way Handshake diagram

Thank you for visiting our website! If you have any queries or if you want to talk about anything you can join our community on our Facebook page “Computer Science“. and you can ask whatever is on your mind right now. You can suggest to us any topic that you want us to explain just like this article.

Table of Contents

Share This Post With Your Friends

Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on telegram
Share on whatsapp
Share on email
Share on print
Share on tumblr
Share on pinterest
Share on vk
Share on odnoklassniki
Aftab Ahmed

Aftab Ahmed

I am a student of Computer science and I explain the topics of Computer Science in a way that everyone can understand. My job is to make the topics simple for everyone so that they don't have to read through long and difficult books in order to understand the concepts.

Symmetric and Asymmetric Cryptography explained

What is Symmetric and Asymmetric cryptography?

If you decided to not read the above articles for some reason let’s have a sneak peek into what those words basically mean. The word Cryptography has been derived from the Greek word “kryptós” which means “Hidden or Secret”. Before we get further into it let’s discuss why do we even need encryption in the first place?

Read More »
TCP Flags - TCP Communication methods

TCP Flags – TCP Communication methods

TCP is a way of Secure communication in which the network makes sure that everything that has been sent has reached its destination without any loss in the packets. It uses the Flags to communicate with the receiver and ask for a confirmation on each packet it sends. It also uses the flags to establish the connection with the receiver so that it can know that receiver is able and willing to receive the data. Here is a detailed description of the most common TCP Flags and their function.

Read More »

8 thoughts on “TCP Handshakes | 3-Way and 4-Way TCP handshake”

  1. My developer is trying to persuade me to move to .net
    from PHP. I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using WordPress on several websites for about
    a year and am anxious about switching to another platform.
    I have heard fantastic things about
    Is there a way I can import all my wordpress content into it?
    Any help would be greatly appreciated!

    1. Yes brother you can backup your data by going to wordpress setting menu but then you can only restore that data on a wordpress site if you want to shift to another platform then you need to do it manually by copying the whole content and pasting it on your other platform

  2. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time
    a comment is added I get three e-mails with the same comment.
    Is there any way you can remove people from that service?
    Thanks a lot!

  3. A motivating discussion is definitely worth comment.
    I do think that you should publish more on this topic, it may not be
    a taboo subject but typically people don’t discuss such issues.
    To the next! Best wishes!!

Leave a Comment

Your email address will not be published.