Knowledge

Sliding Window Protocol: How It Works, Types, and Examples

The sliding window protocol is a networking technique that lets a sender transmit several data frames before waiting for an acknowledgement (ACK). It coordinates the sender and receiver so data arrives reliably without overwhelming the receiver or wasting network capacity. It is a core idea in reliable data transfer and a practical foundation for understanding TCP. Instead of sending one packet and pausing after every transmission, the protocol keeps a controlled number of packets “in flight.” That simple change can make a major difference in links with latency.

What Is the Sliding Window Protocol?

The sliding window protocol is a flow-control and error-control mechanism used at the data-link and transport layers. The sender is allowed to send frames whose sequence numbers fall within a permitted range called the send window. As acknowledgements arrive, that range moves – or slides – forward, allowing more frames to be sent.

The receiver has its own receive window, which defines the sequence numbers it is prepared to accept. Together, the two windows help prevent three common problems:

  • A fast sender flooding a slower receiver
  • An idle network link while the sender waits unnecessarily
  • Lost or corrupted frames causing data to be delivered out of order or duplicated

The key idea in plain language

Imagine a warehouse loading dock with room for four outgoing boxes at a time. The shipper can send four boxes before confirmations begin returning. Each confirmation frees one dock position, so another box can leave. The available positions move forward continuously – just like a sliding window.

How the Sliding Window Protocol Works

Each transmitted frame carries a sequence number. The sender tracks which frames have been sent but not yet acknowledged, while the receiver tracks which frame numbers it can accept.

Here is a simple flow with a sender window size of four:

Step Sender action Window state
1 Sends frames 0, 1, 2, and 3 Frames 0–3 are awaiting ACKs
2 Receiver confirms frame 0 Window advances to 1–4
3 Sender sends frame 4 Frames 1–4 may be in flight
4 More ACKs arrive The window continues moving forward

If an ACK does not arrive before a timer expires, the sender treats the related frame as lost and retransmits according to the protocol variant being used.

Why Sliding Windows Improve Network Performance

The main advantage is better link utilization. In a stop-and-wait system, the sender transmits one frame and must remain idle until its acknowledgement returns. On a long-distance or high-latency connection, much of the available bandwidth sits unused. With a sliding window, the sender can keep sending while earlier frames are travelling across the network. The best window size depends on the bandwidth-delay product: the amount of data a path can hold while a signal makes a round trip.

For example, suppose a network can carry 10 Mb/s and has a 100 ms round-trip time. Roughly 1 megabit of data can be in transit during that interval. A window that is far smaller than this leaves capacity unused; a sensibly sized window can keep the path busy.

sliding window protocol

Sliding Window Protocol Components

  • Sequence numbers – Sequence numbers identify individual frames or segments. They allow receivers to detect duplicates, identify missing data, and restore the correct order when packets arrive out of sequence.
  • Sender window – The sender window specifies the range of sequence numbers that the sender may transmit without receiving additional acknowledgements. Frames in this range may be unsent, sent, or awaiting acknowledgement.
  • Receiver window – The receiver window defines which frames the receiver will accept. Its size determines whether the receiver can buffer out-of-order data or must wait for a missing frame first.
  • Acknowledgements and timers – ACKs report successful receipt. Timers detect likely loss: if acknowledgement is not received in time, the sender retransmits. Some implementations use cumulative ACKs, while others acknowledge individual frames.

Types of Sliding Window Protocol

Protocol Frames allowed before ACK What happens after loss Typical trade-off
Stop-and-Wait 1 Resend the missing frame Simple, but inefficient on delayed links
Go-Back-N Up to N Resend the missing frame and all later unacknowledged frames Easier receiver design, may repeat useful work
Selective Repeat Up to N Resend only the missing or damaged frames Efficient, requires buffering and more logic

Stop-and-Wait: the baseline

Stop-and-wait ARQ is a window protocol with a window size of one. The sender sends one frame, waits for an ACK, and then sends the next frame. It is easy to implement but performs poorly when the transmission delay is small compared with the round-trip delay.

Go-Back-N ARQ

In Go-Back-N, the sender may transmit up to N frames without waiting. The receiver generally accepts only the next expected frame and discards later frames that arrive out of order.

If frame 2 is lost after frames 0, 1, 2, 3, and 4 are sent, the receiver accepts 0 and 1 but cannot advance past the missing frame 2. When the sender’s timer expires, it retransmits frame 2 and every subsequent unacknowledged frame. This makes the receiver simpler, but it can waste bandwidth if later frames have already reached the destination correctly.

Selective Repeat ARQ

In Selective Repeat, the receiver can accept and buffer correctly received frames that arrive out of order. The sender retransmits only the frames that were lost or corrupted.

Using the same example, if frame 2 is lost but frames 3 and 4 arrive, the receiver stores frames 3 and 4 and waits for frame 2. Once frame 2 is received, it can deliver the complete sequence in order. This improves efficiency on unreliable links, but requires more memory and careful sequence-number management.

Sliding Window Protocol Example

Assume a sender has a window size of 4 and sends frames 0–3.

  1. Frames 0, 1, 2, and 3 leave the sender.
  2. Frame 1 is lost in transit, but frames 0, 2, and 3 reach the receiver.
  3. The receiver acknowledges frame 0.
  4. In Go-Back-N, the receiver discards 2 and 3 because it is still waiting for 1. The sender eventually retransmits 1, 2, and 3.
  5. In Selective Repeat, the receiver buffers 2 and 3. The sender retransmits only 1; then the receiver can assemble frames 0–3 in order.

This example shows why Selective Repeat is often more efficient when losses occur, particularly on networks where retransmissions are expensive.

Sliding Window Flow Control vs. Congestion Control

These concepts are related but solve different problems:

  • Flow control protects the receiver. It limits transmission based on how much data the receiving device can accept and buffer.
  • Congestion control protects the network. It reduces traffic when routers, links, or the wider path show signs of overload.

TCP is a familiar real-world example. Its advertised receive window communicates receiver capacity, while its congestion window adapts to conditions in the network. The usable amount of outstanding data is constrained by the smaller of those two limits.

Advantages and Limitations

Advantages

  • Increases throughput by allowing multiple frames to travel at once
  • Uses bandwidth more effectively than stop-and-wait communication
  • Provides a structured method for detecting loss, duplication, and ordering issues
  • Balances speed and reliability through the selected window size and retransmission method

Limitations

  • Requires sequence-number tracking, timers, and acknowledgement handling
  • A window that is too small reduces throughput; one that is too large can exhaust receiver buffers
  • Go-Back-N can retransmit data that the receiver already received successfully
  • Selective Repeat is more complex and needs extra receiver-side buffering

Sliding Window Protocol and TCP

The sliding-window concept is central to TCP, though TCP is more sophisticated than textbook data-link protocols. TCP tracks bytes rather than simply numbered frames, uses cumulative acknowledgements, and can use selective acknowledgements to describe gaps in received data. It also adjusts its effective sending rate according to both receiver capacity and network congestion.

That is why a slow application at the receiving end and congestion in the network can each limit a TCP transfer- even if the physical link itself is fast.

Conclusion

The sliding window protocol keeps reliable transmission moving without asking the sender to pause after every frame. By permitting a controlled amount of unacknowledged data, it improves throughput while preserving flow control and reliable delivery. Go-Back-N favors simpler handling; Selective Repeat favors efficiency after loss. Understanding those trade-offs makes TCP behavior and general network performance much easier to explain.

Knowledge

Address Space Layout Randomization (ASLR): How It Works and Why It Matters

Address space layout randomization (ASLR) is a security technique that makes memory-based attacks harder to...

Wormhole Switching: How It Works, Benefits, and Limits

Wormhole switching is a network flow-control technique that divides a packet into small pieces called...

Cut-Through Switching: How It Works, Benefits, and Trade-Offs

Cut-through switching is a network switching method designed to reduce latency. Instead of waiting for...