Networking
TCP
Also known as: Transmission Control Protocol
TCP (Transmission Control Protocol) is a connection-oriented transport protocol that guarantees reliable, ordered delivery of data between two endpoints. It's the foundation of web, email, and file transfer traffic.
TCP sits at the transport layer of the network stack, above IP and below application protocols like HTTP and SMTP. It takes a stream of data from an application and breaks it into segments, each numbered for reassembly, then transmits them over IP — which doesn't guarantee delivery or order.
How TCP establishes a connection
Before any data is sent, TCP performs a three-way handshake to establish a connection:
- SYN — the client sends a synchronization request
- SYN-ACK — the server acknowledges and sends its own sync
- ACK — the client acknowledges the server's sync
Only after this handshake does data flow. This setup provides both endpoints with sequence numbers used to detect lost packets and request retransmission.
TCP vs UDP
TCP's reliability has a cost: latency. The handshake, acknowledgments, and retransmission add overhead. For applications that need every byte delivered correctly — HTTP, HTTPS, email, file transfer, SSH, iSCSI — TCP is the right choice. For applications that prioritize speed over guaranteed delivery (DNS, VoIP, video streaming, gaming), UDP avoids the overhead by dropping the guarantees.
TCP also handles flow control (matching transmission speed to receiver capacity) and congestion control (backing off when the network is congested), which makes it resilient to varying network conditions.