Table of Contents
TCP, or Transmission Control Protocol, gives two applications a reliable, ordered stream of bytes over an IP network. IP addresses and routes packets. TCP uses ports, sequence numbers, acknowledgments, and retransmission to manage delivery between the applications.

How TCP opens and closes a connection
- The client sends SYN with its starting sequence number.
- The server sends SYN-ACK to acknowledge it and provide its own starting number.
- The client sends ACK, completing the normal three-way handshake.
Each direction of the connection can close separately. A FIN means one side has finished sending, and the other side can still send until it closes its direction. RST resets a connection rather than closing it gracefully.

How TCP keeps bytes in order
TCP divides outgoing data into segments. Sequence numbers track bytes in the stream. A cumulative acknowledgment identifies the next byte the receiver expects, so it can cover many bytes at once. If parts arrive out of order, the receiver can hold them while waiting for the missing bytes. TCP can retransmit when it detects loss or a timer expires.
The receive window limits how many bytes the sender can have in flight based on the receiver’s capacity. Congestion control separately adjusts sending to account for network conditions. These mechanisms help recover from loss, but TCP does not guarantee delivery within a fixed time. Applications still need timeouts and error handling.
What is in a TCP header?
The header is at least 20 bytes and grows when options are present. Common fields include:
- Source and destination ports: Identify application endpoints. The pair of IP addresses and pair of ports identify a TCP connection.
- Sequence and acknowledgment numbers: Track positions in the byte stream.
- Flags: Indicate events such as opening, acknowledging, closing, or resetting the connection.
- Data offset, receive window, and checksum: Give the header size, advertised receive capacity, and a way to detect accidental corruption.
For the exact layout, see RFC 9293. The TCP checksum does not encrypt or authenticate your traffic. A protocol such as TLS can provide those protections.
Where TCP fits
SSH and HTTP/1.1 or HTTP/2 commonly use TCP. UDP provides datagrams and leaves any delivery guarantees to the application or a higher-level protocol. For example, HTTP/3 uses QUIC over UDP. Read more about TCP versus UDP and how IP routers move packets between networks.
Reader Comments 0
Sign in with email or Google to join the discussion.