TCP Three-Way Handshake

TCP requires a connection to be established between two end systems before data transfer can begin. TCP establishes the connection using a process that is called the TCP three-way handshake. This process involves setting the SYN bit and ACK bit in the segments between the two devices. An important function that is performed during connection establishment is that the devices exchange their initial sequence numbers (ISNs). This number is used to track data bytes on this connection.

TCP Three-Way Handshake

TCP Connection Setup Procedure
Step Action Notes
1 The initiating device sends a TCP SYN (a TCP segment with the SYN bit set) to the receiving device, starting the handshake process by presenting its initial sequence number. Host A is telling Host B: “Hey, I’d like to start a connection. My initial sequence number is 100.”
2 The receiving device responds with a TCP SYN/ACK (a TCP segment with the SYN and ACK bits set) acknowledging the peer’s initial sequence number and presenting its own initial sequence number. Host B is telling Host A: “I’m accepting your connection request. My initial sequence number is 300. I’m acknowledging your initial sequence number of 100. The next byte of data I expect to receive from you is byte number 101.”
3 The initiating device responds with a TCP ACK (TCP segment with the ACK bit set), acknowledging the initial sequence number of the receiving device. Host A is telling Host B: “Great. I’m acknowledging your initial sequence number of 300. The next byte of data that I expect from you is byte number 301. The hosts are now ready for two-way data exchange.”

A TCP connection is normally and gracefully terminated when each side of the connection closes its side of the connection independently. The following example provides a simplified description of the process:

  • Host A sends a FIN (a TCP segment with the FIN bit set) to Host B to indicate that it wants to terminate the session.
  • Host B sends an ACK (a segment with the ACK bit set) back to Host A, acknowledging that it received the FIN.
  • Host B sends a FIN to Host A.
  • Host A sends an ACK to Host B.

 

Leave a Comment