TCP Segment Structure
You'll learn: How TCP organizes data into segments with headers that manage reliable, ordered delivery.
What Is a TCP Segment?
A TCP segment is the fundamental unit of data transmission in TCP. Think of it like a postal envelope: the actual data (your letter) goes inside, but the envelope itself has critical information—addresses, tracking numbers, and stamps—needed to deliver it reliably and in order.
The TCP segment consists of two main parts:
- Header (20–60 bytes): Control information
- Data (payload): The actual application data being transmitted
Anatomy of the TCP Header
The header contains fields that enable TCP's reliability and ordering guarantees:
Essential Fields
- Source/Destination Port (16 bits each): Identify sending and receiving applications
- Sequence Number (32 bits): Marks the position of this segment's first data byte in the stream. If you're sending bytes 1000–1499, the sequence number is 1000
- Acknowledgment Number (32 bits): Tells the sender "I've received everything up to byte X; send byte X next"
- Flags (9 bits): Control bits including:
SYN: Synchronize, used in connection setupACK: Acknowledgment field is validFIN: Finish, gracefully close connectionRST: Reset connectionPSH: Push data to application immediately
- Window Size (16 bits): Flow control—how many bytes the receiver can accept
- Checksum (16 bits): Error detection for header and data integrity
Analogy
The sequence number is like page numbers in a book—even if pages arrive out of order, you can reassemble them. The acknowledgment number is your receipt confirmation: "I got pages 1–50; please send page 51 next."
Key Takeaway: TCP segments wrap application data in headers containing sequence/acknowledgment numbers, control flags, and checksums to provide reliable, ordered, error-checked delivery over unreliable networks.