Medium Access Control — CSMA, CSMA/CD, CSMA/CA
Stochastic medium access: listen, defer, transmit, detect collisions. The mechanism behind classic Ethernet and Wi-Fi.
What it is#
Medium Access Control (MAC) is the sub-layer of the data link layer that decides who gets to transmit on a shared medium and when. On a point-to-point fibre between two switches there is nothing to decide; on a cable shared by ten hosts, or on a Wi-Fi channel shared by every laptop in a coffee shop, someone has to arbitrate or every transmission turns into a noisy overlap.
CSMA — Carrier Sense Multiple Access — is the family of stochastic, decentralised MAC protocols that powers classic Ethernet (CSMA/CD) and Wi-Fi (CSMA/CA). The recipe is the same in both: listen to the medium, only transmit when it’s idle, and have a strategy for what to do if you discover that someone else transmitted at the same time. The variants differ on whether you can detect collisions (you can on coax cable, you mostly can’t on radio) and so on how you avoid them.
When to use it#
You don’t “choose” CSMA — you inherit it from the medium. The questions are: what kind of medium do I have, and what variant applies?
- Half-duplex shared wired medium (classic 10BASE-5 / 10BASE-T over a hub, some industrial buses) — CSMA/CD. Almost extinct in mainstream LANs.
- Wireless (Wi-Fi, some IoT radios) — CSMA/CA. You cannot reliably detect collisions on radio while transmitting (your own signal drowns out everyone else’s), so you avoid collisions instead of detecting them.
- Modern switched full-duplex Ethernet — neither. Each host has its own collision-free link to a switch port. The MAC layer is still 802.3, but the CSMA/CD state machine never fires because the medium is never shared.
- High-determinism networks (industrial control, broadcast TV uplinks) — TDMA or token-based MAC instead. CSMA’s stochastic backoff is incompatible with hard real-time guarantees.
If you are designing a new wireless protocol from scratch (LoRa, BLE, Zigbee), CSMA/CA-like schemes are common but not universal. CDMA, FHSS, and pure ALOHA still have niches.
How it works#
The core CSMA loop is “listen before you talk”. Three behaviours differ across variants:
- What you do when the channel is busy (1-persistent, non-persistent, p-persistent).
- Whether you keep listening while transmitting (CD only) or commit to a full frame (CA).
- How you handle collisions when they happen.
Pure CSMA (no collision handling)#
loop: sense the medium if idle: transmit done else: wait (strategy-dependent) retry- 1-persistent: as soon as the medium goes idle, transmit. High collision risk when many stations are waiting.
- Non-persistent: when busy, wait a random time, then re-sense from scratch. Lower collision, higher latency.
- p-persistent: when idle, transmit with probability
p; otherwise wait one slot and try again. A tuning knob.
CSMA/CD — Collision Detection (classic Ethernet)#
On a coax cable, a station can listen to the line while transmitting. If the voltage it sees doesn’t match what it’s putting out, someone else is transmitting too — a collision. The station aborts, jams the line (so every other station also notices), and backs off:
attempt = 0loop: sense medium until idle, then transmit if collision detected: transmit jam signal attempt += 1 if attempt > 16: give up backoff = random(0, 2^min(attempt, 10) - 1) * slot_time wait backoff retry else: successThis is binary exponential backoff (BEB). The retry window doubles with each collision, capping at 2^10 - 1 = 1023 slots. After 16 attempts the frame is dropped. Slot time on 10/100 Mb Ethernet is 51.2 µs — long enough that any collision on the longest legal cable run will be detected by every station before the slot ends.
CSMA/CA — Collision Avoidance (Wi-Fi)#
A Wi-Fi station’s own transmission is millions of times stronger than any incoming signal at its receiver. It can’t hear collisions while transmitting. So instead of detecting, it tries to avoid: every transmission is preceded by a random backoff inside a contention window, and the receiver must explicitly acknowledge the frame:
sense medium until idle for DIFSchoose backoff = random(0, CW) * slot_timecountdown while medium stays idle (pause if busy)transmit when timer hits 0wait for ACK from receiverif no ACK: CW = min(CW * 2, CW_max) retryDefault DIFS (DCF Inter-Frame Space) is 34 µs in 802.11a/g/n. Initial contention window CW_min is 15; doubles on each failure up to CW_max = 1023. The absence of an ACK is the only collision signal — the sender assumes loss means collision and backs off.
RTS / CTS — handling the hidden terminal#
Two stations A and C may both be in range of access point B but not in range of each other. A’s carrier sense will not detect C’s transmission to B, so A may transmit and collide at B. RTS/CTS is an optional handshake:
- A sends a tiny Request-to-Send to B, naming the duration of the upcoming transmission.
- B replies Clear-to-Send. Every station that hears the CTS (including C) sees the duration and stays silent.
- A transmits its data frame.
RTS/CTS is overhead-heavy and turned off by default for small frames; access points usually enable it above a threshold (e.g. 2000-byte payloads).
Variants#
- Slotted ALOHA — the historical ancestor. Stations transmit only at slot boundaries; no carrier sense. Max throughput ~37%. Mostly a teaching example.
- CSMA/CD — IEEE 802.3 classic Ethernet (10BASE-T over hubs, 100BASE-TX in half-duplex mode). Almost extinct.
- CSMA/CA — IEEE 802.11 Wi-Fi DCF. The default mode for almost all consumer Wi-Fi.
- CSMA/CA + PCF / HCF — optional Wi-Fi modes that add a polling phase for time-critical traffic. Rarely deployed.
- EDCA (802.11e) — Enhanced Distributed Channel Access. Layers traffic classes on top of CSMA/CA with different DIFS and CW per class — gives voice and video priority over best-effort.
- CSMA/CR — Collision Resolution. Used in CAN bus for automotive networks. Stations with higher-priority IDs dominate the bus by bit-arbitration; no random backoff.
Trade-offs#
Other trade-offs:
- Throughput vs fairness. Binary exponential backoff is fair on average over many attempts but unfair on short timescales — a station that just got through has a smaller contention window than one that’s been backing off.
- Latency vs collision rate. Smaller
CW_minmeans lower latency but more collisions when the channel is busy. LargerCW_minsmooths things out but hurts short-message latency. - Capture effect. A station that consistently succeeds tends to keep its
CWat minimum, while losers keep doubling theirs. On Wi-Fi this looks like one device “hogging” the air — not malice, just exponential backoff doing its thing asymmetrically. - Hidden terminals. RTS/CTS fixes them at a cost in overhead. The cost is unacceptable for tiny frames; the alternative is to accept higher collision rates and let TCP retransmit.
Why doesn't modern switched Ethernet need CSMA/CD?
A full-duplex link from host to switch has two unidirectional channels — one transmit, one receive — and only one device on each. There’s nobody to collide with. The 802.3 standard still includes the CSMA/CD machinery and 10/100/1000BASE-T NICs still implement it for backwards compatibility with half-duplex hubs, but the collision detector never fires on a modern network. The standard committee considered removing it from 10G+ Ethernet entirely; they kept it for symmetry.
Common pitfalls#
- Confusing CSMA/CD with CSMA/CA. CD is for wired (detect collisions). CA is for wireless (avoid collisions). Mixing them up in an interview is a tell.
- Assuming Wi-Fi is full-duplex. It is not — radios on a single channel are half-duplex. Wi-Fi 6’s OFDMA looks duplex-ish at the protocol layer but the underlying medium is still half-duplex per channel.
- Forgetting backoff is per-attempt, not per-frame. A frame retried 5 times has a backoff window of
2^5 = 32slots, not 5 slots. - Trusting the channel-utilisation graph. Wi-Fi tools show “channel utilisation” but include only what the radio can hear. A hidden terminal contributing collisions is invisible until RTS/CTS lights it up.
- Believing CSMA/CA throughput equals link rate. A 100 Mbps Wi-Fi advertised link delivers ~50 Mbps of UDP throughput at best, less with acknowledged TCP. Overhead is real.
- Ignoring duplex mismatch. A 100BASE-TX port forced to full-duplex on one side and half-duplex on the other will technically work — but late collisions on the half-duplex side look like CRC errors that BEB never sees. Symptom: works fine at low load, falls apart under traffic. Always autonegotiate or hard-set both ends.
- Running real-time traffic over best-effort CSMA. Stochastic backoff cannot guarantee bounded latency. If you need it, use a TDMA-style protocol or a dedicated radio.
Related building blocks#