Transmission Control Protocol (TCP)
The Transmission Control Protocol (TCP) is one of the core protocols of the Internet protocol suite. It is a connection-oriented, reliable, byte-stream protocol. TCP provides guaranteed delivery of data and ordering of data packets, making it suitable for applications where data integrity and order are critical, such as web browsing, email, and file transfer.
Key Characteristics of TCP
- Connection-Oriented: Before data transfer begins, TCP establishes a connection between the sender and receiver using a three-way handshake.
- Reliable: TCP ensures that data is delivered without errors and in the correct order. It uses acknowledgments and retransmissions to achieve reliability.
- Ordered Data Delivery: TCP segments are numbered, allowing the receiver to reassemble them in the correct sequence.
- Flow Control: TCP manages the rate of data transmission to prevent a fast sender from overwhelming a slow receiver.
- Congestion Control: TCP dynamically adjusts the transmission rate based on network congestion, helping to avoid network collapse.
- Full-Duplex: Data can be sent and received simultaneously between two connected hosts.
The TCP Three-Way Handshake
The process of establishing a TCP connection involves three steps:
- SYN (Synchronize): The client sends a SYN packet to the server to initiate a connection. This packet contains the client's initial sequence number.
- SYN-ACK (Synchronize-Acknowledge): The server receives the SYN packet, acknowledges it by sending back a SYN-ACK packet, and sets its own initial sequence number.
- ACK (Acknowledge): The client receives the SYN-ACK packet and sends a final ACK packet back to the server, confirming the connection.

TCP Segment Structure
A TCP segment is the unit of data exchanged between TCP entities. It consists of a header and a data portion.
+----------------+--------+--------+----------------+--------+--------+----------------+ | Source Port | Dest Port | Sequence Number | Ack Number | +----------------+--------+--------+----------------+--------+--------+----------------+ | Data Offset | Reserved | Flags | Window Size | Checksum | Urgent Pointer | +----------------+--------+--------+----------------+--------+--------+----------------+ | Options (if any) | +--------------------------------------------------------------------------------------+ | Data (Payload) | | | +--------------------------------------------------------------------------------------+
Common TCP Flags:
- SYN: Synchronize sequence numbers.
- ACK: Acknowledgment number is valid.
- FIN: Sender has finished sending data.
- RST: Reset the connection.
- PSH: Push the data to the application layer immediately.
- URG: Urgent pointer is valid.
Reliability Mechanisms
TCP uses several mechanisms to ensure reliable data transfer:
- Sequence Numbers: Each byte of data is assigned a sequence number, allowing the receiver to reorder segments and detect missing ones.
- Acknowledgments (ACKs): The receiver sends acknowledgments to the sender to confirm that data has been received. Cumulative ACKs are common, meaning an ACK for sequence number N acknowledges all bytes up to N-1.
- Retransmission: If the sender does not receive an acknowledgment for a segment within a certain timeout period, it retransmits the segment.
- Checksum: A checksum is calculated for the header and data to detect corruption during transmission.
Flow Control and Congestion Control
TCP employs sophisticated algorithms for flow and congestion control:
- Sliding Window: The receiver advertises a "window size," indicating how much data it is currently able to receive. The sender must not send more data than this window allows. This is a form of flow control.
- Congestion Avoidance Algorithms (e.g., Slow Start, Congestion Avoidance): These algorithms help TCP probe the network for available capacity and adapt its sending rate to avoid overwhelming routers and causing packet loss.
TCP is a fundamental protocol for modern internet communication, providing a robust and dependable channel for applications that require high data integrity.