Definition:
- TCP is a transport-layer protocol providing reliable, ordered, connection-oriented byte-stream delivery between two hosts
- Runs on top of IP (the “TCP/IP” stack)
- Used when correctness matters more than speed: HTTP(s), email (SMTP), file transfer (FTP/SFTP), SSH
Connection-oriented:
- A connection must be established before any data is sent — 3-way handshake:
SYN → client requests to open, sends its initial sequence number
SYN-ACK → server acknowledges and sends its own sequence number
ACK → client acknowledges; connection established
- Tear-down uses a 4-way handshake (
FIN/ACK in each direction)
Reliability mechanisms:
- Sequence numbers: every byte is numbered so the receiver can reorder
- Acknowledgements (ACK): receiver confirms receipt; sender retransmits on timeout / missing ACK
- Checksum: detects corrupted segments
- Retransmission: lost segments are resent
Flow & congestion control:
- Flow control: a sliding window stops a fast sender from overwhelming a slow receiver
- Congestion control: slow start, congestion avoidance, fast retransmit/recovery throttle sending when the network is congested
Overhead:
- Header is 20–60 bytes (larger than UDP’s 8)
- Handshake + ACKs + ordering add latency and head-of-line blocking
- See User Datagram Protocol for the lightweight, connectionless alternative
- QUIC layers TCP-like reliability over UDP to cut handshake latency