advanced23 min studyLesson 181 in Engineering

TCP sequence numbers describe bytes, not messages

Reconstruct byte ranges, cumulative acknowledgments, duplicate delivery, and sequence-number wrap without confusing transport receipt with application success.

On this page

What you’ll understand

  • Calculate the next expected byte after contiguous delivery.
  • Interpret a cumulative acknowledgment when later ranges arrive first.
  • Separate transport receipt, application parsing, and durable business effects.

Imagine a receiver has collected the middle of a file but is missing its beginning. Counting arriving packets cannot tell the application which complete bytes are safe to read next. TCP instead names positions in each direction's byte stream. This lesson turns a capture into a range ledger: write what was sent, mark what is missing, and ask exactly what an acknowledgment proves before inferring anything about the application.

Build a ledger of half-open byte ranges

An established TCP segment's sequence number normally identifies its first payload byte. A payload of length L beginning at S covers the half-open interval [S,S+L): it includes S and excludes S+L. This notation makes adjacent ranges fit without overlap. Retransmission can divide the same bytes into different segments, so packet boundaries are not permanent message boundaries. A receiver can return one application read containing several writes, or several reads containing one write. The application needs its own framing rule, such as a length prefix, before it can recover records.

The acknowledgment number names the next byte expected in order. If all bytes below 5,000 are present but byte 5,000 is missing, the cumulative acknowledgment remains 5,000 even when later data has arrived. Do not subtract one twice: ACK 5,000 acknowledges bytes through 4,999, relative to that direction's sequence space. The two directions have independent sequence numbering. A packet carrying both payload and an ACK simultaneously advances one ledger and reports progress on the other; its two numbers need not be numerically related.

payload range=[S,S+L),A=min⁡{b:byte b is missing in order}\text{payload range}=[S,S+L),\qquad A=\min\{b:\text{byte }b\text{ is missing in order}\}
S and A are byte positions, and L is a byte count. The missing-byte interpretation assumes an established connection and contiguous acknowledgment state; actual header arithmetic is modulo 2^32.↔ Scroll wide equations horizontally.

Account for control flags and circular numbering

SYN and FIN each consume one sequence number even though neither is an application payload byte. With initial sequence number 900, a SYN occupies position 900 and the first ordinary data byte begins at 901. A FIN after the last payload byte similarly needs acknowledgment. An ACK-only segment consumes no new sequence position. These distinctions matter when checking a handshake or a half-close: a one-position difference may represent a control flag rather than a missing character, and closing one sending direction does not automatically close the other direction.

The header contains a 32-bit sequence field, so its displayed value eventually wraps. A numerically smaller value can be later in the stream. TCP comparisons use circular sequence-space rules together with windows and lifetime protections, not an unrestricted unsigned less-than comparison. For a short trace, unwrap positions into a larger local integer coordinate only when the connection context makes the ordering unambiguous. Reusing a four-tuple or ignoring the handshake can incorrectly combine distinct connections. A capture's convenient relative sequence numbers are an analysis convention rather than extra fields sent on the wire.

Snext=(S+L+ISYN+IFIN) mod 232S_{\rm next}=(S+L+I_{\rm SYN}+I_{\rm FIN})\bmod 2^{32}
Each indicator is one when that control flag occupies sequence space, otherwise zero. Sequence positions are dimensionless byte indices; this modular update alone is not a complete rule for comparing arbitrary distant sequence numbers.↔ Scroll wide equations horizontally.

Say what the evidence does and does not establish

A cumulative ACK reports transport-level receipt into the receiving TCP's ordered stream. It does not establish that an application parsed a record, committed a database transaction, or persisted a file across power loss. A connection failure after a server received a payment request but before the client received the response therefore leaves an application-level ambiguity. Request identifiers and a durable deduplication contract solve a different problem from retransmitting TCP bytes. Transport reliability prevents duplicate stream bytes from being delivered as repeated positions; it does not make separately retried business requests exactly once.

Use the binomial lab as an intentionally narrower thought experiment about missing pieces. Let success mean delivery of an independently transmitted, equal-role segment, set delivery probability to 0.9, and compare five with ten trials. Predict why the chance that every segment arrives falls as the batch grows even though each segment has the same success chance. The bars count delivered segments, not their locations; they cannot determine a cumulative ACK. Return to your range ledger to locate the earliest hole. Real correlated losses, retransmissions, and reordering are outside this model.

Fill the earliest hole before advancing the ACK

An established receiver expects byte 4,001. It first receives [5,001,6,001), then [4,001,5,001), with no flags and no other missing data. What cumulative ACK follows each arrival?

  1. After the later range arrives, byte 4,001 is still missing. The receiver can buffer 1,000 later bytes, but its cumulative ACK remains 4,001.

  2. The second arrival fills [4,001,5,001). The two adjacent ranges now cover 2,000 consecutive bytes beginning at 4,001.

  3. The next missing byte is 6,001, so the cumulative ACK can advance directly to 6,001. Repeating either segment does not create new stream positions.

The result

The ACK sequence is 4,001 then 6,001. The jump acknowledges contiguous bytes, not a count of packets or proof that the file was saved.

Explore the model

Interactive lab

Interactive lab · probability

A batch can contain a hole

Set success probability p to delivery probability and change trial count n. Inspect the probability bar at n successes. The exact independent binomial model counts delivered pieces; it does not track their order, sequence numbers, ACKs, or retransmissions.

A batch can contain a holeThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAll-piece delivery becomes less likely for larger independent batches; only a byte-range ledger identifies the cumulative ACK.

Check your understanding

A capture shows cumulative ACK 12,001 for an established data direction. Which claim is justified?

Try it yourself

A SYN uses initial sequence number 77. The sender then transmits 200 payload bytes and immediately sends FIN. Give the first data sequence number, FIN position, and ACK after all are received.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Count SYN and FIN as one sequence position each; payload length counts only data bytes.

Compare with the solution

The first data byte is 78. Two hundred bytes occupy [78,278), so FIN occupies position 278. The next expected position is 279, producing ACK 279 after the FIN is accepted. This assumes no wrap or gaps and says nothing about when the application consumes the data.

Take it with you

  • TCP numbers byte positions and consumes extra positions for SYN and FIN.
  • A cumulative ACK stops at the earliest gap despite later buffered data.
  • Transport receipt and an application's durable success are different contracts.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.