1. Home
  2. Computer Networks
  3. Sliding Window Protocol

Sliding Window Protocol

Send many frames before waiting for acknowledgements. Compare Stop-and-Wait, Go-Back-N and Selective Repeat when a frame gets lost — in 3D.

Interactive 3DIntermediate13 min readCNUpdated

Drag to rotate · Right-drag to pan · Click, then scroll to zoom · Space play · Left arrowRight arrow step

What's happening

The sender (back row) must deliver frames 0–9 to the receiver (front row) over an unreliable link. Sliding window protocols send several frames before waiting for acknowledgements. Compare how each protocol recovers from a lost frame.

Pseudocode

  1. send every frame inside the window (up to N)
  2. receiver accepts frames only IN ORDER; ACK k = "all up to k−1 received"
  3. when the oldest frame is ACKed, slide the window forward
  4. on timeout: resend the oldest frame AND everything after it
Read this model as text · 11 steps

One run of the model above, written out step by step. Useful with a screen reader, on a slow connection, or for quick revision. The values may differ from the run on your screen.

  1. The sender (back row) must deliver frames 0–9 to the receiver (front row) over an unreliable link. Sliding window protocols send several frames before waiting for acknowledgements. Compare how each protocol recovers from a lost frame.
  2. Go-Back-N (window 4) — frame 2 will be lost the first time it is sent.
  3. Tick 0: send frames 0, 1, 2, 3; frame 2 is lost on the way ✗.
  4. Tick 1: receiver discards 3 (out of order).
  5. Tick 2: ACK 2 arrives; window slides to start at 2; send frames 4, 5.
  6. Tick 3: receiver discards 4, 5 (out of order); timeout → go back and resend frames 2–5.
  7. Tick 4: ACK 2 arrives.
  8. Tick 5: ACK 6 arrives; window slides to start at 6; send frames 6, 7, 8, 9.
  9. Tick 6: waiting….
  10. Tick 7: ACK 10 arrives; window slides to start at 10.
  11. All 10 frames delivered in 8 ticks with 14 transmissions. Go-Back-N re-sent several good frames after the loss.

Try this in the 3D model

  • Run Go-Back-N with frame 2 lost. Which frames get re-sent after the timeout?
  • Run Selective Repeat with the same loss. Compare the number of transmissions.
  • Run Stop-and-Wait on a perfect link and count the ticks. Why is it so slow?

The problem: waiting wastes time

Data is sent in frames, and the receiver confirms each with an acknowledgement (ACK). If a frame or ACK is lost, the sender retransmits after a timeout. This idea is called ARQ (Automatic Repeat reQuest).

The simplest version, Stop-and-Wait, sends one frame and waits for its ACK before sending the next. On a long link (say India → USA, ~200 ms round trip) the line sits idle most of the time.

The sliding window idea

Let the sender have up to N unacknowledged frames in flight at once. The window is the range of sequence numbers it may send:

[ acked | acked | sent | sent | sent | sent | not yet | not yet ]
                 └──────── window (N = 4) ───────┘

When the oldest frame in the window is acknowledged, the window slides forward and a new frame may be sent. In the 3D model, the translucent box on the sender’s row is the window.

Go-Back-N (GBN)

  • Sender keeps up to N frames in flight.
  • Receiver accepts frames only in order; anything out of order is discarded.
  • ACKs are cumulative: “ACK k” means everything before k arrived.
  • On timeout, the sender goes back and resends the oldest unacknowledged frame and all frames after it.

Simple receiver, but one loss causes many good frames to be resent.

Selective Repeat (SR)

  • Receiver buffers out-of-order frames and acknowledges each frame individually.
  • On timeout, the sender resends only the missing frame.
  • More efficient on lossy links, but the receiver needs buffer space, and the window can be at most half the sequence-number space (to avoid confusing old and new frames).

Comparison

Stop-and-Wait Go-Back-N Selective Repeat
Sender window 1 N N
Receiver window 1 1 N
Out-of-order frames — Discarded Buffered
ACK type Individual Cumulative Individual
Resent on one loss 1 Up to N 1
Complexity Lowest Medium Highest

Efficiency

With frame transmission time Tf and propagation delay Tp, let a = Tp / Tf. The link utilisation of Stop-and-Wait is

U = 1 / (1 + 2a)

A window of size N ≥ 1 + 2a keeps the link fully busy (U ≈ 1). That’s why TCP uses a sliding window (with a variable size) on top of IP.

Code (Go-Back-N sender, simplified)

def go_back_n(frames, N, lost=None):
    lost = set(lost or {2})                                       # frames lost the first time
    base, next_seq, log = 0, 0, []
    while base < len(frames):
        while next_seq < base + N and next_seq < len(frames):    # fill the window
            log.append(f"send {next_seq}" + (" (lost)" if next_seq in lost else ""))
            next_seq += 1
        # receiver accepts only in-order frames
        expected = base
        while expected < next_seq and expected not in lost:
            expected += 1
        if expected == base:                                      # nothing new arrived → timeout
            log.append(f"timeout → resend {base}..{next_seq - 1}")
            lost.discard(base)
            next_seq = base
        else:
            log.append(f"ACK {expected}")
            base = expected
    return log

for line in go_back_n(list(range(8)), 4):
    print(line)

Common mistakes

  • Thinking Go-Back-N resends all frames — only from the lost one onwards.
  • Forgetting that ACKs can be lost too (a later cumulative ACK still covers earlier frames in GBN).
  • Making the Selective Repeat window bigger than half the sequence space.

Complexity at a glance

Case / operationTimeWhy
Max frames in flightN (window size)
Retransmissions after one loss — Go-Back-Nup to NThe lost frame and everything after it.
Retransmissions after one loss — Selective Repeat1Only the lost frame.
Extra spaceReceiver buffer of N frames (Selective Repeat)

Quick check

Test yourself — pick an answer to see if you got it.

1. In Go-Back-N, what does the receiver do with a frame that arrives out of order?

2. After a timeout, Selective Repeat retransmits…

3. Stop-and-Wait is equivalent to a sliding window of size…

4. Why do sliding window protocols improve throughput?

Saved in this browser.
Spotted a mistake or a bug in the 3D model?

Report a mistake

in Sliding Window Protocol. Thank you — every report makes the lesson better for the next reader.

We'll also include a link to the step of the 3D model you're on and your browser type, so we can reproduce it.