The idea
TCP promises connection-oriented, reliable delivery. Making good on that promise starts with two very concrete things: what is actually inside a TCP segment, and how TCP counts what it has sent so far. Everything in the next three topics — connection setup, flow control, congestion control — refers back to the fields and numbering introduced here.
How it works
TCP, at a glance
TCP provides connection-oriented, reliable communication using sending and receiving buffers. Data is grouped into segments, each carrying a sequencing and numbering scheme, and TCP layers flow control, error control, and congestion control on top of that.
How it works
Sending and receiving buffers
Buffers exist because the application and the network do not move data at the same pace. The sender’s buffer has three regions: bytes already sent, bytes written but not yet sent, and empty space available to receive more from the sending process. The receiver’s buffer has two regions: bytes received but not yet read by the application, and empty space available to receive more from the sender.
TCP segments group a number of bytes together into one packet, with a header added for transmission control. Segments may have different sizes, and the buffer is what actually stores them for transmission.
| Field | Width |
|---|---|
| Source Port | 16 bits |
| Destination Port | 16 bits |
| Sequence Number | 32 bits |
| Acknowledgment Number | 32 bits |
| Data Offset (Header Length) | 4 bits |
| Reserved | 6 bits |
| Flags | 6 bits (URG, ACK, PSH, RST, SYN, FIN) |
| Window (Receive Window) | 16 bits |
| Checksum | 16 bits |
| Urgent Pointer | 16 bits |
| Options and Padding | variable |
How it works
TCP flags
Five of the six flag bits are given a meaning directly:
- ACK — Acknowledgment.
- PSH — Transmit data.
- RST — Reject connection.
- SYN — Synchronise process.
- FIN — Finish process.
Aside
The Flags field is named as 6 bits — URG, ACK, PSH, RST, SYN, FIN — but this material only defines the meaning of the other five. It does not spell out what URG signals, so this page does not state one.
How it works
TCP numbering system
TCP tracks segments through two fields, and both of them are byte numbers, not frame or segment numbers. All data bytes are numbered with 32 bits, and numbering runs independently in each direction — it does not necessarily start at 0.
- Sequence number — the byte number of the first data byte contained in that segment. The very first segment of a connection carries the ISN, the Initial Sequence Number, chosen as a random number.
- Acknowledgment number — the number of the next byte a party expects to receive.
Where marks get lost
TCP counts bytes, not frames
Stop-and-Wait numbers frames modulo-2; Go-Back-N numbers frames modulo 2^m. TCP does neither — it numbers individual bytes, in a 32-bit space that does not reset per segment and does not start from 0. A question that treats a TCP sequence number as if it counted segments, the way an ARQ sequence number counts frames, has mixed up two different numbering schemes.
Worked example
Sequence numbers across five segments
A TCP connection is transferring a file of 5000 bytes. The first byte is numbered 10001. The data is sent in five segments, each carrying 1000 bytes. What is the sequence number of each segment?
Segment 1 — sequence number 10001, covering bytes 10001 to 11000.
Segment 2 — sequence number 11001, covering bytes 11001 to 12000. Each segment’s sequence number is simply the byte number one past the end of the previous segment’s range.
Segment 3 — sequence number 12001, covering bytes 12001 to 13000.
Segment 4 — sequence number 13001, covering bytes 13001 to 14000.
Segment 5 — sequence number 14001, covering bytes 14001 to 15000.
AnswerSegment 3's sequence number is 12001, covering bytes 12001 to 13000.
In the exam
- Memorise the header field widths as a set: Source Port 16, Destination Port 16, Sequence Number 32, Acknowledgment Number 32, Data Offset 4, Reserved 6, Flags 6, Window 16, Checksum 16, Urgent Pointer 16, Options and Padding variable.
- The Checksum is compulsory for TCP — do not describe it as optional error detection.
- Sequence number = the byte number of the segment’s first byte. Not the segment’s position in a count of segments.
- The ISN is random, not zero, and only applies to the first segment of a connection.
- Reproduce the 5000-byte, first-byte-10001 example exactly if asked to compute sequence numbers across multiple equal-sized segments — the pattern is “previous end + 1.”
Check yourself
- A TCP segment’s header carries 11 fields; know each width, especially the two 32-bit numbering fields and the 6-bit Flags field.
- ACK, PSH, RST, SYN, FIN have defined meanings in this material; URG does not.
- TCP sequence numbers count bytes, in a 32-bit space, independently in each direction — never frames.
- The ISN starting a connection is random; every later sequence number in that direction follows from it by adding bytes sent.