TCP.html
* created: 2026-05-18T18:16
* modified: 2026-06-08T20:01
title
Title
description
Description
Transmission Control Protocol
A connection-oriented protocol that aims to enable reliable communication between client and host, using the following error control mechanisms:
- Sequence numbers
- Checksum
- Positive Acknowledgments
- Backwards error correction
It also provides:
- Flow control
- Congestion avoidance
- Unicast and Duplex (no Multicast)
When sending an acknowledgment TCP uses the number of the bytes it expects next, e.g., if we receive bytes 0-3999 we would send an ack 40000, meaning, we received everything up until but not including byte 4000.
Uses Sockets and Ports
Session
Handshake:
SYN: Client sends a synchronization request -- with the SYN-bit being set
SYN-ACK: Server response with an acknowledgment containing the initial sequence number (ISN) -- with the SYN- and ACK-bit being set
ACK: Client response with an acknowledgment -- with the ACK-bit being set
Disconnect:
FIN: Clients sets disconnect request
FIN-ACK: Server acknowledges and also sends disconnect request
ACK: Client acknowledges, and the connection is closed (after a grace period)
The grace period ensures that the client can resend the acknowledgment if the server didn't receive it.
Sliding Window
Send multiple packages without waiting for acknowledgment to increase efficiency. This allows the sender to transmit n packages at ones. If the first package is acknowledged, then the sender can shift the window by one.
The sender typically also batches acknowledgments. TCP uses go-back-n, i.e., all packets that came after n have to be retransmitted in case of an error.
Note: Finding the optimal window size -> Sawtooth Pattern
RTT: Round Trimp Time (packet send - packet ack)
RTO: Retranmission Timeout (calculated from RTT)
Segmentation
TCP segmentation bridges the gap between TCP's byte-stream abstraction and the packet-based reality of the network. During connection setup, both sides negotiate a Maximum Segment Size (MSS), typically 1460 bytes on Ethernet, which caps how much payload each segment can carry. The sender's kernel buffers application writes and orders them into segments constrained by MSS, the receiver's advertised window, and the congestion window. Nagle's algorithm further unifies small writes to avoid flooding the network with tiny packets, at the cost of some latency.
On the receiving end, segments are held in a reorder buffer and delivered to the application only once the byte stream is contiguous, using sequence numbers to detect gaps.