Sub topic 11
CSMA/CD: detecting collisions while transmitting
This chapter explains how CSMA/CD (Carrier Sense Multiple Access with Collision Detection) lets stations share one wire. It assumes you know the following:
- How pure and slotted ALOHA work.
- What carrier sensing and persistence mean.
- Bandwidth, transmission delay and propagation delay.
Binary exponential backoff and minimum frame size get their own chapters. Here you will see how they fit into the protocol.
The idea
ALOHA transmits blindly. CSMA listens first. CSMA/CD adds one more step. The station keeps listening while it transmits, and it stops at once if it hears another signal on top of its own.
On a wired shared medium this saves a lot of time. A collided frame is useless, so there is no reason to finish sending it. Aborting early frees the channel within a short, bounded time, instead of after a whole frame time.
CSMA/CD combines three rules:
- Carrier sense. Before sending, a station checks whether the medium is idle.
- Collision detection. While sending, the station compares what it puts on the wire with what it reads back. A mismatch, or abnormal signal energy, means a collision.
- Backoff. After a collision the station waits a random time before retrying.
The transmission procedure
Classic Ethernet uses 1-persistent CSMA with collision detection. A station with a frame follows these steps:
- Sense the medium. If it is busy, keep sensing until it becomes idle.
- When the medium is idle, wait the interframe gap (9.6 µs on 10 Mbps Ethernet) and start transmitting.
- While transmitting, monitor for a collision.
- If no collision is detected by the end of the frame, the transmission succeeded.
- If a collision is detected, stop sending the frame and send a short jam signal (32 bits). The jam makes sure every other station notices the collision.
- Increment the collision counter. If the counter reaches 16, abort and report failure. Otherwise wait a backoff time and go back to step 1.
Why a collision can happen at all
Carrier sense is not perfect because signals take time to travel. Suppose stations A and B sit at opposite ends of a cable with one-way propagation delay T.
- At time 0, A senses an idle channel and starts sending.
- Just before time T, A's signal has not yet reached B. B also senses an idle channel and starts sending.
- B's signal collides with A's almost immediately, and B notices the collision at once.
- The garbled signal needs another time T to travel back to A. A learns of the collision at about time 2T.
So the worst-case time for a sender to detect a collision is 2T, the round-trip propagation time. If A has already finished sending before 2T, it will believe the frame was delivered. That leads to the minimum frame size rule, covered in its own chapter: a frame must last at least 2T.
Contention slots and the shape of time
The channel alternates between three states:
- Transmission periods, when one station is sending a frame successfully.
- Contention periods, when stations collide and back off.
- Idle periods, when nobody has anything to send.
The contention period is divided into slots of length 2T, called the slot time. A station can be sure it has acquired the channel only after it has transmitted for one full slot without hearing a collision. For 10 Mbps Ethernet the slot time is 51.2 µs, which equals 512 bit times.
Backoff delays are counted in slot times. The code below is the backoff rule from the topic plan. After the n-th collision, the wait is a random whole number of slots from 0 to 2^min(n,10) − 1.
import random
def backoff_slots(collision_count):
if collision_count >= 16:
return None # give up: the frame is dropped after 16 attempts
k = min(collision_count, 10)
return random.randrange(2 ** k) # wait this many slot times
for n in (1, 2, 3, 10, 12, 16):
print(n, backoff_slots(n))The range doubles after each collision until it is capped at 1024 slots after ten collisions. This makes the protocol adapt to load. With few contenders, the first retry usually succeeds. With many contenders, the growing range spreads their retries out.
Worked example: how soon can two stations resolve a collision?
Two stations collide for the first time. Each picks a backoff from {0, 1}, each value with probability 1/2.
- The two stations pick different values with probability 2 × (1/2 × 1/2) = 1/2. The one with the smaller value transmits first. The other station senses the busy channel and defers.
- They pick the same value with probability 1/2. They collide again.
After the second collision each picks from {0, 1, 2, 3}. The probability of picking the same value is 4 × (1/4 × 1/4) = 1/4. So the probability that two stations are still colliding after the second round is 1/2 × 1/4 = 1/8 in total.
In general, after the i-th collision the chance of a repeat collision between two stations is 1/2^i, while i ≤ 10.
Frame size, bandwidth and the distance limit
The minimum frame length must cover the round trip:
minimum frame bits = bandwidth × round-trip time
bandwidth_bps = 10_000_000 # 10 Mbps Ethernet
round_trip_time_s = 51.2e-6 # slot time = 2 x propagation delay
min_frame_bits = round(bandwidth_bps * round_trip_time_s)
print(min_frame_bits, min_frame_bits // 8) # 512 64This gives 512 bits, or 64 bytes. The same relation can be turned around to find the longest cable for a given frame size: the round-trip time cannot exceed the transmission time of the shortest frame. If you raise the bandwidth and keep the frame size at 64 bytes, the maximum network diameter must shrink in proportion.
Common errors and edge cases
- Collision detection needs an active sender. A station that has finished sending cannot detect a collision. This is why short frames are padded to the minimum size.
- Late collisions. A collision detected after the first 512 bits points to a cable that is too long or a faulty device. The protocol does not retransmit these automatically at the link layer, so higher layers must recover.
- Detection time is not 1T. GATE questions often ask for the worst case. For stations at opposite ends it is 2T. A station that is closer to the other one detects the collision sooner, so the worst case applies only to the farthest pair.
- Backoff counting. The counter is capped at 10 for the range, but the number of attempts is capped at 16. Do not mix up the two limits.
- Backoff after success. The collision count is per frame. It resets to 0 for the next frame.
- Jam signal. The jam is sent after detection. It is not counted toward the minimum frame size.
- Where it works. CSMA/CD relies on a wired shared medium, where a station can listen while it talks. On wireless networks a transmitter's own signal drowns out other signals, so that approach does not work there. Wireless LANs use CSMA/CA instead.
Summary of the key quantities
| Quantity | Value for 10 Mbps Ethernet |
|---|---|
| Slot time | 51.2 µs (512 bit times) |
| Minimum frame | 64 bytes (512 bits) |
| Interframe gap | 9.6 µs |
| Jam signal | 32 bits |
| Maximum attempts | 16 |
| Backoff range cap | 2^10 = 1024 slots |
Exercise
A 10 Mbps CSMA/CD network has a one-way propagation delay of 25.6 µs between its two farthest stations. (a) What is the worst-case time for a sender to detect a collision? (b) What is the minimum frame size in bytes? (c) After the third collision of one frame, what is the range of backoff values in slot times?
Show answer
(a) The worst case is the round-trip time, 2 × 25.6 µs = 51.2 µs. (b) Minimum frame bits = 10,000,000 × 51.2 × 10^-6 = 512 bits, which is 64 bytes. (c) After the third collision the range is 0 to 2^3 − 1, which is 0 to 7 slot times.
Exercise
Two stations collide on their first attempt for a frame. What is the probability that they collide again on the second attempt, and what is the probability that they collide on both the second and the third attempt?
Show answer
After the first collision each picks from {0, 1}, so they pick the same value with probability 1/2 and collide again. After the second collision each picks from {0, 1, 2, 3}, so the repeat probability is 1/4. Collision on the second attempt has probability 1/2. Collision on both the second and third attempts has probability 1/2 × 1/4 = 1/8, provided both attempts are counted as collisions that follow from the first.