ELEC3506

Topics

Transport LayerLecture 7 PDF18 min

The TCP segment and its numbering system

Every field in the TCP header, what the six flag bits mean, and how TCP numbers every byte rather than every frame.

By the end of this page you should be able to

  • Name every TCP segment header field and its bit width
  • State what each of the five commonly used TCP flags means
  • Explain what a TCP sequence number counts, and why that differs from an ARQ frame sequence number
  • Compute the sequence number of each segment when a byte stream is split across multiple segments

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.

FieldWidth
Source Port16 bits
Destination Port16 bits
Sequence Number32 bits
Acknowledgment Number32 bits
Data Offset (Header Length)4 bits
Reserved6 bits
Flags6 bits (URG, ACK, PSH, RST, SYN, FIN)
Window (Receive Window)16 bits
Checksum16 bits
Urgent Pointer16 bits
Options and Paddingvariable
The TCP segment format, field by field. The Checksum is compulsory for TCP — it is the segment's error-detection mechanism.

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?

  1. Segment 1 — sequence number 10001, covering bytes 10001 to 11000.

  2. 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.

  3. Segment 3 — sequence number 12001, covering bytes 12001 to 13000.

  4. Segment 4 — sequence number 13001, covering bytes 13001 to 14000.

  5. 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.

Check yourself

  1. A TCP connection transfers a 5000-byte file. The first byte is numbered 10001, and the data is sent in five segments of 1000 bytes each. What is the sequence number of the third segment?
  2. What does a TCP sequence number count, and how does that differ from a Go-Back-N frame's sequence number?
  3. How many bits wide is the TCP Sequence Number field?
  4. What does the ISN represent, and how is it chosen?
  5. Which TCP flag indicates that data is being transmitted?
  6. The Flags field in a TCP header is 6 bits wide, covering URG, ACK, PSH, RST, SYN, and FIN. Which of these does the lecture define the meaning of?