On an 802.11 channel, how do SIFS, DIFS and the random backoff decide who transmits next, and what changes after a missing ACK?
answer
- the shortest gap wins
- responses ride on SIFS
- slots counted down, frozen when busy
- window grows on failure, resets on success
basics
~20 sSIFS, the shortest gap, lets an ACK or CTS follow its frame before anyone else can contend; a new transmission waits DIFS plus a random backoff. A missing ACK roughly doubles the contention window, up to CWmax.
solid answer
~40 s802.11 gives priority through waiting time. The **SIFS** is the shortest interframe space, used inside an exchange (the ACK after a data frame, the CTS after an RTS, the data after a CTS), so the responder always takes the medium before any contender. A station starting a new transmission must see the medium idle for a **DIFS** (under WMM, an **AIFS** that differs per access category), then counts down a random number of slots drawn from 0 to the contention window. The counter runs only while the medium is idle and freezes, without being redrawn, when someone else transmits; whoever reaches zero first sends. If no ACK returns, the sender retransmits with the window roughly doubled, up to `CWmax`; a success, or reaching the retry limit, resets it to `CWmin`.
code
pseudocode · 19 lines// One station's DCF transmit attempt (no WMM; immediate access on an idle medium omitted)
cw = CWmin
retries = 0
loop:
wait until medium idle (no energy, NAV == 0) for DIFS
backoff = random_integer(0, cw)
while backoff > 0:
wait one slot
if medium busy:
wait until medium idle for DIFS // count is frozen, not redrawn
else:
backoff = backoff - 1
send frame (set Retry bit if retries > 0)
if ACK received within SIFS + ACK time:
cw = CWmin ; done
retries = retries + 1
if retries > retry_limit:
cw = CWmin ; drop frame ; done
cw = min(2 * (cw + 1) - 1, CWmax) // 15 -> 31 -> 63 ...go deeper
Remember the order: SIFS is the shortest gap and belongs to responses such as ACK and CTS; DIFS comes before a new transmission, followed by a random backoff.
Explain the backoff countdown, why it freezes while the medium is busy, and how the contention window grows after a missing ACK and resets after success or the retry limit.
Connect the mechanism to symptoms: erratic latency and rising retries as contenders multiply, frames dropped at the retry limit, and why small frames waste airtime.
Treat contention overhead as a per-frame tax that scales with the number of active stations per channel, and use that to argue for fewer contenders per channel over chasing higher link rates.
## Priority by waiting time The 802.11 MAC has no central scheduler in its ordinary contention mode. It creates priority with **interframe spaces (IFS)**: mandatory idle gaps that a station must observe before it may transmit. A shorter gap wins, because a station waiting for a longer gap sees the medium go busy and defers. The exact microsecond values and the **slot time** depend on the PHY and band, but the order is fixed: | Interframe space | Relative length | Used for | |---|---|---| | **SIFS** (short) | Shortest | The response inside an exchange: ACK after data, CTS after RTS, data after CTS | | **PIFS** (point coordination) | SIFS + one slot | A few cases where the access point takes priority access | | **DIFS** (distributed) | SIFS + two slots | Ordinary contention for a new transmission without WMM | | **AIFS** (arbitration) | SIFS + AIFSN slots, per access category | Contention under WMM; an AIFSN of 2 equals DIFS (the per-category values belong with WMM) | | **EIFS** (extended) | Longer than DIFS | Contention after receiving a frame with errors | Because the ACK and CTS ride on the SIFS, an exchange that has started cannot be interrupted by a contender: by the time anyone else has waited a DIFS, the responder is already on the air. ## The backoff procedure A station with a frame to send runs the distributed coordination function: 1. If the medium has been idle for at least a DIFS when the frame arrives, it may transmit at once. 2. Otherwise it waits for the medium to be idle for a DIFS, then draws a random **backoff count** between 0 and the current **contention window (CW)**. 3. It decrements the count once per idle slot. 4. If the medium becomes busy (energy sensed or NAV running), it **freezes** the count, waits for the medium to be idle for a DIFS again, and resumes from the frozen value. 5. When the count reaches zero, it transmits. 6. It waits a SIFS for the ACK. On success the CW returns to **CWmin**; on a missing ACK it retransmits with a larger CW. ## How the contention window grows Contention window values have the form 2^n - 1 slots; hostapd.conf lists them as 1, 3, 7, 15, 31 and so on up to 32767. After each failed attempt the window grows to the next value, roughly doubling (for example 15, 31, 63, ...) until it reaches **CWmax**, where it stays. Two events reset it to CWmin: a successful transmission, or reaching the **retry limit**, at which point the frame is discarded and higher layers must recover. The growth is the self-correcting part. When the channel is crowded, collisions push the stations involved to wider windows, spreading their next attempts over more slots and making a repeat collision less likely. ## Why the counter freezes instead of restarting - **Fairness.** A station that has already counted down most of its backoff keeps that progress, so it tends to win the next round against a station that just started. - **Stability.** If counters restarted after every busy period, a busy channel would push every station back to the start repeatedly and the slowest-luck station could starve. - **No double penalty.** Only a failed transmission enlarges the window; merely hearing others transmit does not. ## What it means for the WLAN you run - **Overhead is per frame.** Each transmission pays a DIFS, an average backoff of about half the window, its preamble, a SIFS and the ACK. Small frames therefore use airtime poorly, which is why aggregation matters (covered with the 802.11 frame types). - **Collisions rise with contenders.** With many active stations on one channel, two counters reach zero in the same slot more often, retries rise, windows widen, and per-station latency becomes erratic. - **A frame can be dropped by the MAC.** After the retry limit, the frame is gone. Upper layers see loss and, for TCP, slow down, even though the radio link looks up. - **Priority between traffic types** comes from per-category AIFS and window parameters under WMM, a separate subject; the mechanism underneath is the same countdown.
- Why does an 802.11 station freeze its backoff counter when the medium goes busy, rather than drawing a new one?Freezing keeps the progress a station has already made, so the longer it has waited, the closer it is to winning. Redrawing after every busy period would let unlucky stations be pushed back repeatedly and starve on a crowded channel. Only a failed transmission enlarges the window; merely hearing others is not a penalty.
- What happens to an 802.11 frame when the sender reaches its retry limit without an ACK?The MAC discards the frame and resets its contention window to CWmin for the next frame. The loss is passed up silently: there is no error frame on the air. Higher layers see a missing packet, and TCP will treat it as congestion and slow down, even though the radio link itself is still up.
- DIFS is shorter than SIFS, so a new transmission can beat an ACK to the medium.
- The backoff counter is redrawn from scratch every time the medium goes busy.
- After a successful frame the contention window stays at its enlarged size.
- Hearing other stations transmit makes a station double its contention window.
- Every station waits the same fixed delay, so there is no randomness in who sends next.