Cutting the cord: how the world's engineers built Wi-Fi

Channels and overlap

Wi-Fi in the 2.4GHz ISM band uses 14 channels at 5MHz intervals.
(Channels 12 and 13 are not available in North America and there
are other country-specific peculiarities. Channel 14 is a special
case.) However, DSSS transmissions are approximately 22MHz wide, so
the 802.11b standard specifies that two transmissions should be
25MHz apart to avoid undue interference. This is the source of the
common wisdom that you should use channels 1, 6, and 11 to avoid
overlap. However, real life is much messier than what can be
encapsulated in such a simple recommendation.

Receivers typically aren't as good as the IEEE wants them to be,
with the result that a sufficiently strong signal can cause
interference even if it's more than 5 channels away. But using
channels that slightly overlap often works just fine, especially if
the different transmitters are relatively far apart. So if you have
four Wi-Fi base stations, it's probably better to use channels
1-4-8-11 in North America rather than have two base stations sit on
the same channel in the 1-6-11 configuration. In Europe and many
other parts of the world 1-5-9-13 is possible, which provides the
20MHz separation needed for 802.11g and 802.11n. In the 5GHz band
where 802.11a -- and sometimes 802.11n -- lives, the channels are
20MHz wide, although they're still numbered in 5MHz intervals (so
three quarters of the channel numbers remain unused). Some 5GHz
channels are only available if they are not used for other purposes
such as radar, so they're only selected when setting the channel
selection to "auto." This also varies by country.

Of course, these days few of us have the luxury to slice and
dice a wide open 2.4GHz band. It's not uncommon to see a dozen or
more Wi-Fi networks in a residential neighborhood. Fortunately,
just because they're there doesn't mean that all of these networks
are going to interfere much. Most networks are idle most of the
time -- statistical multiplexing for the win. However, if you find
yourself stuck between active Wi-Fi networks, it can pay to
experiment a bit.

In some cases, the best choice is to select the same channel
your neighbours are using. That way, your network and theirs will
politely take turns transmitting. Waiting for your neighbour's
transmissions will reduce your maximum throughput, but they also
wait for you, so you get to transmit at maximum speed when it's
your turn. Alternatively, if you choose a channel that heavily
overlaps with a neighbour's network that is both strong and active,
the two networks won't "see" each other and rather than take turns,
generate interference when they both transmit at the same time,
reducing the usable transmission rates.

Then again, in the case of a more remote network, overlapping
can be the better choice than sharing the same channel. The added
distance reduces the interference, so transmission speed remains
high and your network won't wait for the other's transmissions to
be completed. All else being equal, choose channel 1 or the highest
available option. That way, overlap can only come from one
direction.

Who gets to transmit: media access control

With only one radio channel for sending and receiving and
multiple devices that may have data to transmit, obviously, some
protocol is needed for the devices to play nice and take turns
transmitting. Imagine that you are participating in a conference
call. Having all the participants in the call talking at the same
time is not very effective. Ideally, the different participants
that have something interesting to say should take turns speaking.
Those that have nothing to say can simply remain silent.

A natural courtesy rule is not to interrupt each other -- in
other words, to wait for the other party to finish before talking.
Therefore, the different parties listen to medium before talking,
and refrain from saying anything when someone else is speaking. In
wireless network jargon this is called "carrier sense multiple
access" (CSMA). CSMA solves part of the problem, but CSMA still
allows two devices to start transmitting at the same time after a
previous transmission ends, creating a collision. And unlike with
wired Ethernet, Wi-Fi devices can't detect collisions as they
happen.

The solution to this problem is that, after waiting until an
ongoing transmission has finished, stations that want to transmit
then wait for an additional random amount of time. If they're
lucky, they'll choose a different random time, and one will start
the transmission while the other is still waiting, and a collision
is avoided. This solution is aptly named "collision avoidance"
(CA). The 802.11 media access control layer combines CSMA and CA,
shortened to CSMA/CA. Devices also observe a random time between
packets if they have multiple packets to transmit, in order to give
other systems a chance to get a word in.

The implementation of CSMA/CA used in IEEE 802.11 is called the
"distributed coordination function" (DCF). The basic idea is that
before transmitting a packet, stations choose a random "backoff"
counter. Then, as long as the channel is deemed idle, the stations
decrease their backoff counter by one every slot time. The slot
time is either 9 or 20 microseconds, depending on the 802.11
version at hand. Eventually, the backoff counter reaches zero and
at that point the station transmits its packet. After the
transmission, the station chooses a new backoff value and the story
repeats itself. This way, collisions only occur when two stations
choose the same random backoff value.

If the packet doesn't make it to the intended receiver, it's
retransmitted. Of course, a transmitter needs to know whether a
transmission has been successful or not to decide whether a
retransmission is necessary. For this reason, an IEEE 802.11
station immediately sends back an acknowledgment packet after
receiving a regular (unicast) data packet. (This is not done for
multicast/broadcast packets because there is more than one
receiver. Those packets are simply sent at a very low rate.) If a
transmitter fails to receive this acknowledgement, it will schedule
the packet for retransmission. Once in a while, an acknowledgment
gets lost, so an unnecessary retransmission happens, leading to a
duplicated packet.