Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Course
  • Reading Paths
  • Concept Map
  • How to Read the Diagrams
  • Part 0: What Is a Protocol?10
  • Part 1: Timing and Clocking11
  • Part 2: Encoding and Framing12
  • Part 3: Handshakes13
  • Part 4: Flow Control17
  • Part 5: Transactions19
  • Part 6: Concurrency and Performance17
  • Part 7: Ordering13
  • Part 8: Sharing and Arbitration12
  • Part 9: Deadlock and Liveness13
  • Part 10: Reliability and Recovery20
    • Error Models
    • Parity
    • Hamming Distance
    • CRC
    • ECC and SECDED
    • Forward Error Correction
    • Error Responses
    • Poison and Containment
    • ACK and NAK
    • Sequence Numbers
    • Replay Buffers
    • Go-Back-N or Selective Repeat
    • Idempotency and Safe Replay
    • Link-Level or End-to-End Protection
    • Error Classes and Reporting
    • Recovery and Degradation
    • Interface Protection and Safety
    • The Reliability Budget
    • Protocols Compared: Reliability and Recovery
    • Drills: Reliability and Recovery
  • Part 11: Bring-Up and Link Management10
  • Part 12: Power8
  • Part 13: Shared State and Coherence9
  • Part 14: Security and Isolation7
  • Part 15: Specifying and Verifying11
  • Part 16: Protocols Dissected17
  • Part 17: Capstones5
  • Part 18: Interview Preparation6
Loading lesson

‹Part 10: Reliability and Recovery
  1. Topics
  2. First Principles of Hardware Protocols
  3. Part 10: Reliability and Recovery
  4. Sequence Numbers

Part 10 · Reliability and Recovery · Working (W)

Sequence Numbers

A sequence number on every packet lets the receiver detect loss, duplication and reordering. Why the numbers wrap, how many bits they need for a given window, and the rule that keeps an old packet from being mistaken for a new one.

On this page

    Note

    Level: Working (W) · Answers: What if bits go wrong?

    Before this: ACK and NAK, Window Flow Control

    A link numbers its packets with a 3-bit counter, 0 to 7, wrapping back to 0. The sender is allowed 8 packets outstanding. One day the receiver gets packet 3, expects 4, and receives "0". Is that the new packet 0 after a wrap, meaning 4 to 7 were lost? Or an old packet 0 being resent? The receiver cannot tell, and either guess can deliver wrong data. The counter was one bit too short.

    What do sequence numbers detect, and how many bits do they need?

    The obvious answer, and why it breaks

    The obvious answer is a counter on every packet, wide enough that it rarely wraps. But any finite counter wraps, and on a fast link even a 16-bit counter wraps many thousands of times per second. What matters is not how often it wraps, but whether, at any moment, two packets that could both still be in flight can carry the same number. That depends on the window, not on time.

    The idea: number every packet

    The receiver sees

    Means

    Action

    The number it expects

    In order

    Accept; expect the next

    A number already received

    A duplicate (a resend after a lost ACK)

    Discard; acknowledge again

    A number ahead of the expected one

    One or more packets were lost (or reordered)

    NAK, or buffer it (selective repeat, lesson 10.12)

    Numbers are taken modulo 2^n for an n-bit field. For that to be unambiguous, the set of numbers that can be in flight at once must never contain the same value twice, including old packets that might be resent.

    How many bits

    For a sender that may have up to W packets unacknowledged:

    go-back-N: W≤2n−1,selective repeat: W≤2n−1
    • Go-back-N (the receiver accepts only the next expected packet): W ≤ 2^n − 1. With 3 bits, at most 7 outstanding. With 8 outstanding, a full window of new packets 0 to 7 is indistinguishable from all eight being lost and resent.

    • Selective repeat (the receiver buffers out-of-order packets): the receiver's window and the sender's can be offset by up to W, so the numbers must cover 2W: W ≤ 2^(n−1).

    Diagram
    Window needed (from lesson 10.11): bandwidth x ACK round trip
      e.g. 14.3 million packets/s x 500 ns  ~  7 packets; design for bursts and delays: say 64
    Go-back-N:        64 <= 2^n - 1  ->  n = 7 bits (127)
    Selective repeat: 64 <= 2^(n-1)  ->  n = 7 bits (64)
    The opening link: 8 outstanding with 3 bits breaks go-back-N's rule (8 > 7): one bit too few

    How real protocols chose

    Protocol

    Sequence numbers

    PCI Express data link layer

    12-bit sequence numbers with go-back-N replay, so at most 4,095 TLPs may be unacknowledged.

    TCP

    32-bit byte sequence numbers, with extensions for very fast links where even 32 bits wrap quickly.

    DCLink (step 9)

    8-bit sequence numbers with go-back-N, so at most 255 packets unacknowledged.

    What breaks

    The opening link (illustrative) allowed 8 outstanding packets with a 3-bit number. A burst of errors caused all eight to be lost and resent; the receiver, expecting a new 0, accepted the resent old 0 as new, and from then on delivered every packet one window late, with no error. Limiting the window to 7 (or widening the field to 4 bits) made the ambiguity impossible.

    Why this matters

    Senior lens. Derive the sequence-number width from the maximum number of packets that can be unacknowledged, using the rule for the retransmission scheme (go-back-N: 2^n − 1; selective repeat: 2^(n−1)), and enforce the window limit in hardware, not just in the specification. Then check the wrap logic at the boundary in verification: windows that straddle the wrap point are where comparisons fail.

    Interview

    Asked: "How many sequence bits does a link need?"

    Weak answer: As many as possible, 32 bits.

    Strong answer: Enough that no two packets that could both be in flight, including resends, share a number, which depends on the window, not on time. With go-back-N, n bits allow at most 2^n − 1 unacknowledged packets; with selective repeat, at most 2^(n−1). So I'd size the window from bandwidth times ACK round trip, with margin, then pick n, and enforce the window limit in the sender. PCIe uses 12 bits with go-back-N, so up to 4,095 TLPs outstanding.

    Follow-ups: (1) Why does selective repeat need twice the number space? (2) What goes wrong at the limit?

    Check yourself A go-back-N link has 5-bit sequence numbers. What is its maximum window?

    2^5 − 1 = 31 packets.

    Check yourself Why does the rule depend on the window rather than on how fast the numbers wrap?

    Ambiguity arises only if two packets that could both be in flight (including resends) share a number; the window bounds how many that can be.

    Key takeaways

    • Sequence numbers let the receiver detect duplicates, losses and reordering.

    • Go-back-N needs W ≤ 2^n − 1; selective repeat needs W ≤ 2^(n−1).

    • Size n from the window, enforce the window in hardware, and test windows that straddle the wrap.

    Keep going

    Next: Lesson 10.11, Replay Buffers. Keeping a copy until it is acknowledged: sizing the replay buffer from the round trip.

    Related topics

    • Part 10 overview: Reliability and Recovery

    Previous

    151 / 234

    Next: Replay Buffers

    Up next

    Up nextReplay Buffers

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Error Models
    • Parity
    • Hamming Distance