TCP is a connection‑oriented, reliable transport‑layer protocol. Before any data is exchanged, TCP establishes a session using a three‑way handshake, then guarantees in‑order, error‑free delivery via sequencing, acknowledgments, flow control, and retransmissions. Finally, it cleanly tears down the connection with a four‑step FIN sequence.

Each TCP segment consists of a header (20–60 bytes) and payload.
| Field | Size | Description |
|---|---|---|
| Source Port | 16 bits | Port on the sender’s host (chosen from ephemeral range). |
| Destination Port | 16 bits | Port where the receiving service is listening (e.g., 80 for HTTP). |
| Sequence Number | 32 bits | Byte index of the first data byte in this segment. |
| Acknowledgment Number | 32 bits | Next byte the sender expects to receive (cumulative ACK). |
| Data Offset (HLEN) | 4 bits | Header length in 4‑byte words (min 5 → 20 bytes; max 15 → 60 bytes). |
| Reserved | 3 bits | Reserved for future use; set to zero. |
| Control Flags | 9 bits | URG, ACK, PSH, RST, SYN, FIN, plus ECE, CWR, NS for congestion control. |
| Window Size | 16 bits | Bytes the receiver can accept (flow‑control window). |
| Checksum | 16 bits | Covers header + data for error detection. |
| Urgent Pointer | 16 bits | If URG flag set, points to last urgent data byte. |
| Options & Padding | 0–40 bytes | Extra features (MSS, window scaling, timestamps). |
| Payload (Data) | Variable | The actual application data (up to MSS). |
Establishes a TCP connection and synchronizes initial sequence numbers (ISNs):
| Step | Packet | Description |
|---|---|---|
| 1 | SYN |
Client → Server: “SYNchronize. My ISN = A.” |
| 2 | SYN + ACK |
Server → Client: “ACK your A. My ISN = B, and I SYNc with you.” |
| 3 | ACK |
Client → Server: “ACK your B. Let’s begin data transfer at Seq = A+1, Ack = B+1.” |

Once Step 3 completes, the TCP connection is established.