TCP (Transmission Control Protocol)

Overview

TCP is a connection-oriented, reliable, and byte-stream based protocol that ensures data transmitted between devices on a network arrives completely and in the correct order.

Key Features

Connection Establishment

TCP uses a three-way handshake process to establish a connection:

  1. SYN: Client sends a SYN packet to the server
  2. SYN-ACK: Server responds with a SYN-ACK packet
  3. ACK: Client acknowledges with an ACK packet

Reliability Mechanisms

  • Acknowledgments: Confirmation of received segments
  • Sequence Numbers: Track the order of transmitted data
  • Checksums: Verify data integrity
  • Retransmission: Resend lost or corrupted segments

Flow Control

TCP implements a sliding window protocol that allows the receiver to control how much data the sender can transmit, preventing buffer overflow.

Congestion Control

  • Slow Start: Gradually increases transmission rate
  • Congestion Avoidance: Adjusts window size based on network conditions
  • Fast Retransmit and Recovery: Quickly recovers from packet loss

TCP Segment Structure

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Sequence Number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Acknowledgment Number                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Data |           |U|A|P|R|S|F|                               |
| Offset| Reserved  |R|C|S|S|Y|I|            Window             |
|       |           |G|K|H|T|N|N|                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             Data                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

TCP Connection States

  • LISTEN: Server waiting for connections
  • SYN-SENT: Client has sent SYN, waiting for SYN-ACK
  • SYN-RECEIVED: Server received SYN, sent SYN-ACK
  • ESTABLISHED: Connection established, data transfer possible
  • FIN-WAIT-1: Closing connection, waiting for ACK
  • FIN-WAIT-2: Waiting for FIN from remote
  • CLOSE-WAIT: Remote closed connection, waiting for application to close
  • CLOSING: Both sides closing simultaneously
  • LAST-ACK: Waiting for final ACK
  • TIME-WAIT: Waiting to ensure remote received final ACK
  • CLOSED: Connection fully terminated

TCP Animation

TCP Connection and Data Transfer

Transmission Control Protocol (TCP) provides reliable, ordered, and error-checked delivery of data between applications. This animation demonstrates the TCP three-way handshake and data transfer.

Common Applications

  • Web browsing (HTTP/HTTPS)
  • Email (SMTP, IMAP, POP3)
  • File transfers (FTP, SFTP)
  • Remote terminal access (SSH, Telnet)
  • Database connections