CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 4 · Transport Layer (TCP)

Lesson 4.3.1 · Item 67 of 90

TCP segment header, byte-stream numbering & cumulative ACKs

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. In Go-Back-N and Selective Repeat, what did each sequence number count: a packet/frame, or an individual byte?
    Stuck? Peek at 4.2.4 Selective Repeat (SR): Ws = Wr ≤ 2ᵏ⁻¹ & minimum sequence bits
    • Selective Repeat bounds: Ws = Wr ≤ 2ᵏ⁻¹ ⇒ minimum bits for window N is k = ⌈log₂(2N)⌉.
    • Receiver: buffers out-of-order frames within Wr; sends selective ACKs / NAKs; delivers in order to upper layer.
    • Every K-th tx lost (M frames): Total transmissions in SR = M + ⌊(M − 1) / (K − 1)⌋.

    Read lesson 4.2.4

  2. What four fields make up a TCP connection’s 4-tuple socket identifier?
    Stuck? Peek at 4.1 Transport basics: process-to-process delivery, ports, sockets & multiplexing
    • Delivery: Network Layer = host-to-host; Transport Layer = process-to-process.
    • Port number = 16 bits (0–65,535): Well-known 0–1023, Registered 1024–49151, Ephemeral 49152–65535.
    • Demultiplexing: UDP uses 2-tuple (DstIP, DstPort); TCP uses 4-tuple (SrcIP, SrcPort, DstIP, DstPort).
    • UDP (Foundation) = 8-byte header, connectionless, best-effort; TCP = connection-oriented, reliable, flow + congestion controlled.

    Read lesson 4.1

  3. In the IPv4 header, what does the 4-bit HLEN field count, and what are its minimum and maximum byte sizes?
    Stuck? Peek at 3.2.1 IPv4 header fields: HLEN, Total Length, TTL, Protocol & Checksum
    • Base header = 20 B (`HLEN = 5`); Max header = 60 B (`HLEN = 15`, max 40 B options).
    • Multipliers: `Header = 4 × HLEN`, `Total Length = Header + Payload` (max 65,535 B), `Offset × 8 = start byte`.
    • Per-hop changes: Every router decrements TTL by 1 (drops if 0) and recomputes Header Checksum (which covers IP header only).

    Read lesson 3.2.1

The Hook

In Chapter 4.2 we numbered packets 0, 1, 2, 3, …. Real-world TCP (Transmission Control Protocol) does something even cleaner: it views all data sent by an application as an unstructured, contiguous stream of bytes and gives every single data byte its own 32-bit sequence number!

Let's open up the 20–60 byte TCP segment header and see how byte-stream sequence numbers, cumulative acknowledgements, and the six control flags work together.

Predict First

A TCP sender starts its first data segment at Sequence Number 1000 and places 500 bytes of application data inside the segment. What are the byte numbers of the first and last bytes in that segment, and what Acknowledgement Number will the receiver send back?

,

Counting 500 bytes starting at 1000 gives bytes 1000 through 1499 (NOT 1500, because byte 1000 is the 1st byte: 1499 − 1000 + 1 = 500!). The receiver then sends ACK = 1500, because a TCP Acknowledgement Number always means "the next byte number I expect to receive"!

Core Concept

The 20–60 Byte TCP Segment Header

Like the IPv4 header, the TCP header has a mandatory 20-byte (5 × 32-bit) base header plus 0 to 40 bytes of options, controlled by a 4-bit Header Length (Data Offset / HLEN) field that counts in 4-byte words (5 to 15 → 20 to 60 bytes):

048162431
Source Port (16)16 bits
Destination Port (16)16 bits
Sequence Number (32 bits — byte number of 1st data byte)32 bits
Acknowledgement Number (32 bits — next byte expected)32 bits
HLEN (×4B)4 bits
Reserved (6)6 bits
URG|ACK|PSH|RST|SYN|FIN (6)6 bits
Window Size (16 bits)16 bits
Checksum (16 bits)16 bits
Urgent Pointer (16 bits)16 bits
Options + Padding (0 to 40 bytes, multiple of 4 bytes)32 bits
The TCP segment header (rows 1–5 = 20-byte mandatory header; HLEN scales by ×4 bytes).

Byte-Stream Numbering, ISN, MSS & Cumulative ACKs

Four definitions govern every TCP sequence-number question on GATE:

  • Initial Sequence Number (ISN): At connection setup, each side picks a 32-bit starting number ISN (randomised in practice for security). The SYN flag consumes 1 sequence number (ISN), so the 1st data byte is numbered ISN + 1.
  • Segment Sequence Number: The byte-stream number of the first data byte carried in that segment. If a segment starts at Seq = S and carries L bytes of data, it covers bytes S through S + L − 1, and the next segment starts at S + L.
  • Maximum Segment Size (MSS): The maximum number of application data bytes in one TCP segment (excludes TCP and IP headers! On Ethernet with MTU = 1500 B and 20B IP + 20B TCP headers, MSS = 1500 − 20 − 20 = 1460 bytes).
  • Cumulative ACK Number: When the ACK flag bit is 1, the 32-bit Acknowledgement Number A states that the receiver has received all bytes up through A − 1 in order and next expects byte A.
Seg 1: Seq=1000 (bytes 1000..1499)0–499
Seg 2: Seq=1500 (bytes 1500..1999)500–999
Seg 3: Seq=2000 (bytes 2000..2499)1000–1499
01499
Three 500-byte TCP segments starting at byte 1000: last byte of Segment 1 is 1499, and its ACK is 1500!

The Six Control Flag Bits (URG, ACK, PSH, RST, SYN, FIN)

Each of the six 1-bit flags in Row 4 has a specific role:

Flag BitNameMeaning when set to 1
SYNSynchroniseUsed in connection setup to synchronise Initial Sequence Numbers (consumes 1 sequence number).
ACKAcknowledgeIndicates that the 32-bit Acknowledgement Number field is valid.
FINFinishSender has finished sending data and wants to close its half of the connection (consumes 1 sequence number).
RSTResetAbruptly aborts a connection (or rejects an invalid connection attempt).
PSHPushAsks receiver TCP to pass buffered data up to the application immediately rather than waiting for more data.
URGUrgentIndicates Urgent Pointer field is valid (points to end of urgent data; rarely used today).
The 6 TCP flag bits (SYN, ACK, FIN, RST are heavily tested in GATE).

Putting it together

  • TCP numbers every application data byte with a 32-bit sequence number; a segment’s Seq field holds the number of its first data byte.
  • TCP acknowledgements are cumulative and always state the next expected in-order byte number (Seq + DataLength).
  • The 20–60 byte TCP header carries 16-bit ports, 32-bit Seq/Ack numbers, 4-bit HLEN (×4B), 6 control flags, a 16-bit window, and a 16-bit checksum.

Visual

Hybrid GBN + SR Behaviour in Modern TCP
• TCP headers use CUMULATIVE ACKs (like GBN): if bytes 1000..1499 arrived and 1500..1999 is missing while 2000..2499 arrives, TCP still sends ACK = 1500 (a "duplicate ACK"). • However, modern TCP receivers BUFFER out-of-order segments (like SR) so when 1500..1999 is retransmitted, the receiver immediately advances ACK to 2500!
MSS vs MTU
• MTU (Layer 2 limit) = IP Header + TCP Header + Data (e.g. 1500 B). • MSS (Layer 4 limit) = Data payload ONLY (e.g. 1460 B). Never include the 20B TCP header in MSS!
Two essential TCP facts for GATE.

Worked Examples

Easy

A TCP segment has Sequence Number = 2500 and carries 800 bytes of data. What is the sequence number of the last byte in this segment, and what ACK number does the receiver send after receiving it in order?

Show the full solution

• First byte = 2500.
• Last byte = 2500 + 800 − 1 = 3299.
• Next expected byte (ACK number) = 2500 + 800 = 3300.

Medium

A host receives an IPv4 datagram with Total Length = 1000 bytes, IPv4 HLEN = 5, carrying a TCP segment with TCP HLEN = 8 and TCP Sequence Number = 10,000. What ACK number should the receiver return?

Show the full solution

1) IPv4 header length = 5 × 4 = 20 bytes.
2) TCP header length = 8 × 4 = 32 bytes (20B base + 12B TCP options).
3) TCP data payload = 1000 − 20 − 32 = 948 bytes.
4) Next expected byte = 10,000 + 948 = 10,948.

GATE

Sender A sends three back-to-back TCP segments to Receiver B: Segment 1 (Seq = 100, 200 bytes), Segment 2 (Seq = 300, 200 bytes), and Segment 3 (Seq = 500, 200 bytes). Suppose Segment 2 is lost, while Segments 1 and 3 arrive intact. What ACK numbers does Receiver B send upon receiving Segment 1, upon receiving Segment 3, and finally after Sender A retransmits Segment 2?

Show the full solution

• After Segment 1 (bytes 100..299): B sends ACK = 300.
• After Segment 3 (bytes 500..699, out of order!): B buffers bytes 500..699, but because TCP ACKs are cumulative, B still expects byte 300 first and sends a duplicate ACK = 300!
• After retransmitted Segment 2 (bytes 300..499) arrives: the gap is filled, so B now has all bytes 100..699 contiguous and sends ACK = 700!

GATE Traps

  • MSS does NOT include the TCP header! MSS is purely the maximum application data payload in a TCP segment.
  • Out-of-order arrival still triggers the OLD cumulative ACK! When bytes 500..699 arrive while 300..499 is missing, TCP sends ACK = 300 (not 700!).

Memory Hook

Seq = first byte in the box; ACK = first byte still missing; Last byte = Seq + L − 1!

Connect the Dots

Now that we know the fields of a TCP segment, how do two hosts agree on their starting sequence numbers (ISN) when they establish a connection, and how do they close it cleanly? Next lesson (4.3.2): The 3-way connection setup and connection teardown state machine!

Self-Test

  1. NAT

    A TCP segment starts at Sequence Number 4000 and carries 1200 bytes of application data. What is the sequence number of the LAST byte in this segment?

    Write your answer before opening the key.

  2. NAT

    An Ethernet frame (MTU = 1500 bytes) carries an IPv4 datagram with no IP options (20-byte IP header) and a TCP segment with 12 bytes of TCP options. What is the maximum number of application data bytes (MSS) that this TCP segment can carry?

    Write your answer before opening the key.

  3. MCQ

    Host A has received all bytes up to byte 2000 from Host B. Next, Host B sends Segment 1 (bytes 2001..3000) and Segment 2 (bytes 3001..4000). Segment 1 is lost, and Segment 2 arrives intact at Host A. What Acknowledgement Number does Host A put in the ACK segment it sends in response to Segment 2?

    1. 2000
    2. 2001
    3. 3001
    4. 4001
  4. MSQ

    Which of the following statements about the TCP header are TRUE?

    1. The minimum TCP header size is 20 bytes (HLEN = 5) and the maximum is 60 bytes (HLEN = 15).
    2. The Sequence Number field is 32 bits long and the Port Number fields are 16 bits long.
    3. The TCP Checksum is mandatory and covers the TCP header, TCP data, and a conceptual IP pseudo-header.
    4. The 4-bit HLEN field in the TCP header counts in 8-byte units.

Rule Card

  • TCP Header: 20–60 B (`HLEN × 4`); 16b Src/Dst Ports, 32b Seq #, 32b Ack #, 6 Flags (`URG, ACK, PSH, RST, SYN, FIN`), 16b Window, 16b Checksum.
  • Byte numbering: segment at `Seq = S` with L bytes covers `S .. S + L − 1`; receiver sends cumulative `ACK = S + L` (next expected byte).
  • `MSS` = max TCP data payload per segment (`MTU − IP_hdr − TCP_hdr`).

Concept Ledger

  • TCP segment header
  • HLEN (data offset ×4)
  • TCP flags (URG, ACK, PSH, RST, SYN, FIN)
  • byte-stream numbering
  • ISN (Initial Sequence Number)
  • ACK = next expected byte
  • MSS (Maximum Segment Size)

Answer Vault

Try the questions first. Open when you are ready to check.

Warm-up answers

  1. In Chapter 4.2, each sequence number counted a whole frame/packet (whereas TCP numbers every individual data byte!).
  2. (Source IP, Source Port, Destination IP, Destination Port).
  3. It counts 4-byte (32-bit) words; minimum 5 (20 bytes) and maximum 15 (60 bytes).

Self-test answers

  1. 5199 — Last byte = Seq + Length − 1 = 4000 + 1200 − 1 = 5199 (and the next expected ACK is 5200).
  2. 1448 — TCP header = 20B base + 12B options = 32B. Max TCP data (MSS) = 1500 − 20 (IP) − 32 (TCP) = 1448 bytes.
  3. B — TCP uses cumulative acknowledgements specifying the next expected in-order byte. Since bytes up to 2000 arrived and 2001..3000 is missing, Host A buffers 3001..4000 and sends ACK = 2001.
    • A: Byte 2000 was already received; ACK names the NEXT expected byte (2001).
    • C: Bytes 2001..3000 have not arrived yet.
    • D: ACK 4001 will be sent only after Segment 1 (2001..3000) arrives.
  4. ABC — TCP header is 20–60B, Seq is 32b, Ports are 16b, and Checksum covers pseudo-header + TCP header + data. HLEN counts 4-byte words, not 8-byte units.
    • D: HLEN counts 4-byte (32-bit) words (just like IPv4 HLEN).

Flashcards

  1. If a TCP segment has Seq = 500 and carries 300 bytes of data, what are the last byte number and the resulting ACK number?
    Reveal answerLast byte = 500 + 300 − 1 = 799; ACK number = 500 + 300 = 800.
  2. What is MSS on a standard 1500-byte MTU link with 20B IP and 20B TCP headers?
    Reveal answer1500 − 20 − 20 = 1460 bytes of application data.
  3. What does a TCP cumulative ACK of 4500 mean?
    Reveal answerThe receiver has received all bytes through 4499 in order and is waiting for byte 4500 next.

Exam shortcuts

  • Last Byte vs Next ACK Formula: Next ACK = Seq + DataLength; Last Byte = Seq + DataLength − 1. — never making an off-by-1 error on byte ranges.
  • TCP Data Payload from IP Total Length: TCP_Data = IP_Total_Length − 4×IP_HLEN − 4×TCP_HLEN. — combined IPv4 + TCP header numericals.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.