TCP (Transmission Control Protocol) is a connection-oriented transport layer protocol that provides reliable, ordered, and error-checked data delivery between devices.
- Uses a three-way handshake to initiate communication.
- Assigns sequence numbers to maintain data order.
- Detects transmission errors using a checksum.
- Controls data flow using the sliding window mechanism.

TCP Connection Establishment
TCP establishes a connection using a three-way handshake, where both sender and receiver synchronize sequence numbers and exchange communication parameters before data transfer begins.
Step 1 – SYN (Client -> Server)
The sender initiates the connection by sending a SYN segment.
- Sequence Number (Seq = 521): Random Initial Sequence Number (ISN) generated by sender.
- SYN = 1: Requests synchronization of sequence numbers.
- Maximum Segment Size (MSS = 1460 bytes): Declares the maximum data size it can receive without fragmentation (stored in TCP Options field).
- Window Size (14600 bytes): Advertises its receiving buffer capacity.
Step 2 – SYN + ACK (Server -> Client)
The receiver responds with a SYN-ACK segment, since TCP is full-duplex and both sides must synchronize.
- Sequence Number (Seq = 2000): Receiver’s random ISN.
- SYN = 1: Requests synchronization from sender.
- ACK = 1: Acknowledgment field is valid.
- Acknowledgment Number (Ack = 522): Acknowledges sender’s Seq 521 (SYN consumes one sequence number).
- MSS = 500 bytes: Receiver’s maximum acceptable segment size.
- Window Size (10000 bytes): Receiver’s buffer capacity.
Since MSS(receiver) < MSS(sender), both agree on the smaller MSS (500 bytes) to avoid fragmentation.
- Receiver sending window = 14600 / 500 = 29 segments
- Sender sending window = 10000 / 500 = 20 segments
Step 3 – ACK (Client ->Server)
The sender sends the final acknowledgment to complete synchronization.
- Sequence Number (Seq = 522): Next sequence number after SYN (521 + 1).
- Acknowledgment Number (Ack = 2001): Acknowledges receiver’s Seq 2000 (SYN consumes one sequence number).
- ACK = 1: Confirms acknowledgment field is valid.
After this third segment, the connection enters the ESTABLISHED state.
Because three segments are exchanged (SYN -> SYN+ACK -> ACK), this process is called the Three-Way Handshake.
CP Flags Used
TCP uses specific control flags in the header to manage connection setup and termination.
- SYN (Synchronize): Initiates a new connection and synchronizes initial sequence numbers.
- ACK (Acknowledge): Confirms receipt of a segment and validates the acknowledgment number.
- RST (Reset): Immediately terminates a connection due to errors or invalid requests.
- FIN (Finish): Gracefully closes an established connection after data transfer is complete.
Common Issues
Certain problems may affect the handshake process and delay or prevent connection setup.
- SYN Flood Attack: Large number of incomplete SYN requests exhaust server resources.
- Connection Timeout: Handshake fails if a response is not received within a specified time.
- Packet Loss: Lost SYN or ACK segments require retransmission, increasing delay.
Methods to Optimize TCP Connection
Performance of connection setup can be improved using optimization techniques.
- TCP Fast Open (TFO): Allows data transmission during the initial SYN, reducing handshake latency.
- Keep-Alive Mechanism: Maintains active connections to avoid repeated handshakes.
- Load Balancing: Distributes incoming connections across multiple servers for efficient handling.