Transmission Control Protocol (TCP)
1. Definition
TCP (Transmission Control Protocol) is the connection-oriented, reliable, byte-stream transport-layer (Layer-4) protocol of the Internet. It takes data from an application, breaks it into segments, ensures every byte arrives in order and without loss, and delivers it to the correct application through port numbers. It also performs flow control (protecting the receiver) and congestion control (protecting the network). Defined in RFC 793 and used by HTTP, FTP, SMTP, SSH and almost every application where correctness matters.
2. Features
- Connection-oriented — a connection is established, used and released (handshake and teardown).
- Reliable — sequence numbers, acknowledgements, timeouts and retransmission.
- Ordered — the receiver reassembles segments in sequence; duplicates are discarded.
- Full duplex — data flows both ways at once.
- Byte-stream service — the application sees a continuous stream, not records.
- Flow control — sliding-window mechanism, so a fast sender never overwhelms a slow receiver.
- Congestion control — slow start, congestion avoidance, fast retransmit/recovery; the sender backs off when packets are lost.
- Multiplexing/demultiplexing by port numbers, error detection by checksum, and options such as MSS, window scaling, SACK and timestamps.
0 1 2 3
┌──────────────────────────┬──────────────────────────────────────┐
│ Source port (16) │ Destination port (16) │
├──────────────────────────┼──────────────────────────────────────┤
│ Sequence number (32) │
├─────────────────────────────────────────────────────────────────┤
│ Acknowledgement number (32) │
├──────┬──────┬────────┬──────────┬───────────────────────────────┤
│Dataof│Flags │Window │Checksum │Urgent pointer │
│(4) │(SYN, │(16) │(16) │(16) │
│ │ACK, │ │ │ │
│ │FIN..)│ │ │ │
├──────┴──────┴────────┴──────────┴───────────────────────────────┤
│ Options + padding (MSS, SACK, window scale, timestamps) │
└─────────────────────────────────────────────────────────────────┘
The three-way handshake synchronises initial sequence numbers in both directions and confirms that each side can both send and receive. Closing uses four steps (FIN, ACK, FIN, ACK) because each direction is closed independently.
5. Reliability Mechanisms
- Sequence numbers — every byte is numbered, so losses, duplicates and reordering are detected.
- Cumulative acknowledgements — "I have received all bytes up to N".
- Retransmission on timeout (RTO) — the timer is computed from the measured round-trip time.
- Fast retransmit — three duplicate ACKs imply a lost segment, so it is resent immediately without waiting for the timer.
- Selective acknowledgement (SACK) — reports exactly which blocks were received, avoiding resending everything.
- Checksum — detects corruption; the segment is discarded and retransmitted.
- Flow control — the receiver advertises a window; a zero window tells the sender to pause.
- Congestion control — the sender keeps a congestion window
cwnd, starts small (slow start, doubling each RTT), switches to linear growth (congestion avoidance), and cutscwndwhen loss is detected (AIMD — additive increase, multiplicative decrease).
6. TCP in Action
Applications and their well-known ports: HTTP 80, HTTPS 443, FTP 20/21, SSH 22, Telnet 23, SMTP 25, DNS 53 (zone transfer/large replies), POP3 110, IMAP 143, MySQL 3306, RDP 3389.
Worked example (sequence numbers): a client sends a segment with sequence number 5000 carrying 1000 bytes of data. The receiver acknowledges with ack = 6000 — meaning "next byte I expect is 6000", i.e. bytes 5000-5999 were received successfully.
Throughput and window: with a receive window of 64 KB and an RTT of 100 ms:
This is why a fat, long path needs a big window (window scaling) — otherwise a single TCP connection cannot fill a fast link.
7. Advantages and Limitations
| Advantages | Limitations |
|---|---|
| Guaranteed, in-order, loss-free delivery | Header 20+ bytes and ACK traffic = overhead |
| Flow and congestion control protect receiver and network | Handshake adds latency before data can flow |
| Works over any unreliable network | Retransmissions add delay — bad for real-time media |
| Full duplex, widely supported, well understood | Head-of-line blocking: one lost segment stalls the stream |
| Congestion-friendly to other traffic | More CPU/memory per connection (state, buffers, timers) |
8. Exam Points
- Define TCP; list its features — 5 marks, almost certain.
- Explain the TCP header fields — 5 marks.
- Explain the three-way handshake and connection termination with a diagram — 5-7 marks, very frequent.
- How does TCP provide reliability? (sequence numbers, ACKs, timeouts, retransmission) — 5-7 marks, frequent.
- Explain flow control (sliding window) and congestion control (slow start, AIMD) — 5 marks.
- Numerical on sequence/acknowledgement numbers or window/RTT throughput — 3-5 marks.
- Differentiate TCP and UDP (tabular) — 5 marks, almost certain.