← All chapters
Chapter 15· 9 min read · illustrated

TCP — The Reliable Backbone

Connection-oriented delivery, the 3-way handshake, and the graceful close

TCP is the workhorse of the internet — HTTP, email, and most APIs ride on it. Where UDP shrugs at lost data, TCP guarantees your bytes arrive, complete and in order. It buys that reliability by first setting up a connection.

Interactive — the TCP handshake, live

A sequence diagram that actually runs: handshake, data, graceful close — with connection states on both sides. Drop a packet and watch TCP recover.

Client127.0.0.1:3000Server10.0.0.1:443CLOSEDLISTENtime ↓

Client CLOSED, server LISTEN — nothing has happened yet. The client speaks first.

Network
01

What is TCP?

TCP (Transmission Control Protocol) provides reliable, ordered, error-checked delivery of a stream of bytes between two applications. If something is lost, TCP resends it; if things arrive out of order, TCP reorders them. Its data unit is the segment.

Tap to enlarge
02

Connection-oriented

Unlike UDP, TCP is connection-oriented: before any data is sent, both sides establish a connection and agree on starting parameters. Only then does data flow. This setup is what makes tracking and reliability possible.

Tap to enlarge
03

The 3-way handshake

Connections open with a three-way handshake:

1. SYN
Client → Server: "I want to talk, my starting sequence number is x."
2. SYN-ACK
Server → Client: "OK, my starting number is y, and I acknowledge x."
3. ACK
Client → Server: "I acknowledge y." Connection established.
Tap to enlarge
04

Why three steps?

Three messages are the minimum for both sides to confirm they can each send and receive. The client learns the server hears it; the server learns the client hears it back. Two messages would leave one direction unconfirmed.

Tap to enlarge
05

Closing the connection

Closing is a four-way exchange because each side shuts down its own direction independently: one side sends FIN, the other ACKs it; then the other side sends its own FIN, which gets ACKed. This lets data still flow one way while the other way is already closed.

Tap to enlarge
06

What TCP gives you

Reliable
Lost segments are detected and retransmitted.
In-order
Sequence numbers reassemble the stream correctly.
Flow control
Never overwhelms a slow receiver.
Congestion control
Backs off when the network is busy.
Tap to enlarge
07

Connection states

A TCP connection moves through named states — LISTEN, SYN-SENT, ESTABLISHED, FIN-WAIT, CLOSED, and more. You will see these in tools like netstat and ss when debugging. ESTABLISHED is the healthy, data-flowing state.

Tap to enlarge