Skip to content

Level 8 · Chapter 8.7

From modems to Ethernet: sending bits over a wire

How bits become signals: modulation and QAM with a worked constellation, baud versus bit/s, dial-up, DSL, cable and fiber, line codes up to PAM4, the Ethernet frame and its CRC computed live, and this Mac's Wi-Fi rate derived from first principles.

Inside a computer, a bit is a voltage on a wire a few millimeters or centimeters long. Between computers, the wire is a telephone line, a coaxial cable, a twisted pair, an optical fiber or empty air, meters to thousands of kilometers long, and a plain "high means 1, low means 0" signal doesn't survive the trip. This chapter looks at how bits are turned into signals that do: modulation, line codes and frames. Why signals weaken and distort along a wire is covered by signals on wires and fibers, at the physics level; the protocols above the frame belong to networking, beyond this book's scope.

Why not just send the voltages

A real channel only carries a limited range of frequencies — its bandwidth. A telephone line was designed for the human voice and, once it passes through the phone network, carries only about 300 to 3,400 Hz. A square wave of 0s and 1s is made of many frequencies (its sharp edges are high-frequency components), and a channel that removes some of them smears the edges until 0s and 1s blur together. A long run of identical bits is also a problem: many channels, like a phone line, don't pass a constant voltage at all.

So instead of sending the bits themselves, a transmitter sends a carrier, a sine wave at a frequency the channel carries well, and varies it according to the data. That's modulation; a device that modulates and demodulates is a modem.

Amplitude, frequency, phase

A sine wave has three things you can change:

ModulationWhat changesA 1 might be…A 0 might be…
amplitude (ASK)the height of the wavea loud wavea quiet (or no) wave
frequency (FSK)its pitcha higher tonea lower tone
phase (PSK)where in its cycle it startsshifted by 180°not shifted

Early modems used frequency shift keying: the 300 bit/s modems of the 1960s–1970s sent two tones in each direction, which you could hear. Each fixed-length time interval in which the transmitter sends one state of the signal is a symbol. The number of symbols per second is the baud rate; the number of bits per second is the bit rate. They're equal only if each symbol carries exactly one bit. Tanenbaum stresses the difference, and people still confuse them.

With 4 possible phases (45°, 135°, 225°, 315°), each symbol carries 2 bits — Tanenbaum's "dibit phase encoding", nowadays called QPSK. In general, a symbol chosen from M possibilities carries log₂ M bits.

QAM: amplitude and phase together

Quadrature amplitude modulation (QAM) changes both the amplitude and the phase. The neat way to see it: any sine wave at the carrier frequency is the sum of a cosine with amplitude I and a sine with amplitude Q. Pick I and Q from a small set of levels, and each symbol is a point in the (I, Q) plane: a constellation.

16-QAM uses four levels on each axis, −3, −1, +1 and +3, for 16 points and 4 bits per symbol. The first two bits choose I, the last two choose Q, using a Gray code so that neighbouring levels differ in only one bit: 00 → −3, 01 → −1, 11 → +1, 10 → +3.

            Q
   0010   0110 | 1110   1010      +3
                |
   0011   0111 | 1111   1011      +1
  --------------+--------------  I
   0001   0101 | 1101   1001      -1
                |
   0000   0100 | 1100   1000      -3
    -3     -1       +1     +3

To send 1011, the transmitter sends one symbol with I = +3 (bits 10) and Q = +1 (bits 11). The receiver measures I and Q, which noise has moved a little, and picks the nearest point. Thanks to the Gray code, the most likely mistake — picking a neighbouring point — corrupts only one bit, which error-correcting codes then fix.

More points means more bits per symbol but points closer together, so less noise is needed to confuse them. 64-QAM carries 6 bits per symbol, 256-QAM 8, 1024-QAM 10, 4096-QAM 12. How many a channel can use depends on its signal-to-noise ratio, and systems pick the densest constellation the channel supports, adjusting it continuously. The limit is Shannon's formula, C = B · log₂(1 + S/N): a phone channel of about 3,000 Hz with a signal 35 dB (3,162 times) above the noise can carry at most about 35,000 bit/s, whatever the modulation. The physics chapter on signals explains where the formula comes from.

Dial-up, DSL, cable and fiber

That's why dial-up modems stopped where they did. With ever more elaborate QAM, the V.34 standard reached 33,600 bit/s, close to Shannon's limit for an analog phone channel. The last step, 56 kbit/s (V.90), worked only downstream, and only because the provider's end was connected digitally to the phone network, removing one conversion to analog and its noise. Tanenbaum describes 56 kbit/s modems as "modern"; dial-up is now history, used by almost no one.

DSL escaped the voice channel by using the telephone wire itself, which can carry much higher frequencies than the voice network. The book's description of ADSL is accurate: the spectrum up to about 1.1 MHz is split into 256 channels 4,312.5 Hz wide, and each channel runs its own QAM, with as many bits per symbol as its noise allows — up to 15. Its example of 224 downstream channels × 15 bits × 4,000 symbols/s = 13.44 Mbit/s checks out; this is OFDM (orthogonal frequency-division multiplexing), in its DSL form called DMT. The same idea — many narrow carriers, each with its own QAM — now runs Wi-Fi, 4G and 5G, digital TV and cable.

Cable networks, in the book, use 64-QAM downstream. The current standard, DOCSIS 3.1, switched to OFDM with up to 4096-QAM. The book's caption says QAM-64 "allows 6 bits/Hz"; strictly, it carries 6 bits per symbol. How many bits per hertz that gives depends on how many symbols per second fit in each hertz.

Both are being replaced by fiber to the home. A PON (passive optical network) shares one fiber from the provider among many homes through passive optical splitters: GPON carries 2.5 Gbit/s downstream, XGS-PON 10 Gbit/s in both directions. In fiber, the bits are pulses of infrared light, and the link carries far more than any copper line could.

Line codes: when the wire is yours

On a short cable that you control, like a network cable between a computer and a switch, you can send the bits as voltage levels after all — but not naively. A line code maps bits to signal levels so that the receiver can recover the clock (there must be enough transitions), the signal averages to zero (it can pass through the transformers that isolate each end), and it fits in the cable's bandwidth.

CodeIdeaUsed in
NRZ (non-return-to-zero)1 = high, 0 = lowsimple serial links, many fast lanes once scrambled
Manchesterevery bit has a transition in the middle: low→high for 1, high→low for 010 Mbit/s Ethernet (10BASE-T)
4B5B + MLT-34 bits sent as 5 with guaranteed transitions, then cycled through three levels100 Mbit/s Ethernet (100BASE-TX), 125 Mbaud
PAM-5five voltage levels, 2 bits per symbol per pair1 Gbit/s Ethernet (1000BASE-T)
PAM4four levels, 2 bits per symbol50, 100 and 200 Gbit/s Ethernet lanes, PCI Express 6.0

Manchester makes clock recovery trivial, but it needs two signal changes per bit: 10 Mbit/s Ethernet has a baud rate of 20 million. Faster links can't afford that. Gigabit Ethernet over ordinary copper cable uses all four twisted pairs at once, in both directions simultaneously, each carrying 125 million symbols per second with 2 data bits each: 4 × 125 × 2 = 1,000 Mbit/s. And the fastest links have moved from two levels to four: PAM4 doubles the bits per symbol at the cost of a smaller gap between levels, so it needs strong error correction. Like QAM, it trades noise margin for bits.

The Ethernet frame

Bits on a wire need structure: where does a message start and end, who is it for, and did it arrive intact? Ethernet sends frames:

FieldBytesPurpose
preamble + start-of-frame delimiter7 + 1alternating 1s and 0s to let the receiver lock its clock, then a marker
destination address6the receiver's 48-bit MAC address
source address6the sender's MAC address
EtherType2what the payload is: 0x0800 for IPv4, 0x86DD for IPv6
payload46–1,500the data, padded to at least 46 bytes
frame check sequence4a CRC-32 of the frame

followed by a gap of at least 12 byte times before the next frame. A full frame of 1,500 bytes of payload takes 1,538 byte times on the wire, an efficiency of 97.5%. The shortest frame, 64 bytes from destination to CRC, takes 84; at 1 Gbit/s, that's 1,488,095 frames per second at most, a number network equipment is benchmarked against.

Every network interface has its own MAC address, burned in by its manufacturer. On the Mac this chapter was written on, networksetup -listallhardwareports lists 15 hardware ports — the built-in Ethernet port, Wi-Fi, six Thunderbolt ports that can carry networking, a Thunderbolt bridge and six more Ethernet adapters — each with its own address (the last three bytes masked here):

Hardware Port: Ethernet
Device: en0
Ethernet Address: a4:fc:14:xx:xx:xx

Hardware Port: Wi-Fi
Device: en1
Ethernet Address: a4:fc:14:xx:xx:xx

The CRC-32 at the end detects transmission errors. It treats the frame's bits as a huge polynomial, divides it by a fixed 33-bit polynomial, and sends the remainder. The division is just shifts and XORs, which is why hardware computes it at line rate. Here it is in C, bit by bit, on the standard test string — and again with a single bit flipped:

Live · CRC-32, the Ethernet frame check sequence

Try it: Press Step to run one instruction, Run to animate or Continue to finish; the L2–L7 buttons zoom in and out one level at a time.

C source — click a line number for a breakpoint
  1. unsigned int crc32(char *p, int n) {
  2. unsigned int crc = 0xFFFFFFFF;
  3. for (int i = 0; i < n; i++) {
  4. crc = crc ^ (p[i] & 0xFF);
  5. for (int k = 0; k < 8; k++) {
  6. if (crc & 1) crc = (crc >> 1) ^ 0xEDB88320;
  7. else crc = crc >> 1;
  8. }
  9. }
  10. return ~crc;
  11. }
  12. int main() {
  13. char msg[] = "123456789";
  14. unsigned int c = crc32(msg, 9);
  15. printf("%08x\n", c);
  16. msg[3] = msg[3] ^ 1; /* flip one bit on the wire */
  17. printf("%08x\n", crc32(msg, 9));
  18. return 0;
  19. }
step 0
Loading emulator…
Your program as you wrote it: the current line, its variables by name, and its output.

It prints cbf43926, the published check value of this CRC — the same as Python's zlib.crc32(b"123456789") — and then 00a8ea83 for the corrupted message: a completely different value, so the receiver discards the frame. CRC-32 detects every single-bit error, every burst of up to 32 bits, and all but about one in four billion random corruptions. It only detects: recovering the frame is left to higher layers, which resend it.

Tanenbaum's Ethernet was a shared cable on which every computer listened and waited for silence before sending. Today's Ethernet is switched: every device has its own full-duplex cable to a switch port, which forwards each frame only toward its destination address. There are no collisions to manage anymore.

Wi-Fi: QAM in the air

Wi-Fi carries Ethernet-style frames over radio, with OFDM: the channel is split into hundreds or thousands of narrow subcarriers, each carrying QAM symbols. system_profiler SPAirPortDataType reports this Mac's current link:

PHY Mode: 802.11ax
Channel: 85 (6GHz, 160MHz)
Signal / Noise: -59 dBm / -93 dBm
Transmit Rate: 1441
MCS Index: 7

That's Wi-Fi 6E, in the 6 GHz band, on a 160 MHz channel, with a signal-to-noise ratio of −59 − (−93) = 34 dB. The link rate of 1,441 Mbit/s can be rebuilt from the standard's parameters:

ParameterValue
data subcarriers in a 160 MHz 802.11ax channel1,960
MCS 764-QAM (6 bits) with a 5/6 error-correcting code: 5 data bits per subcarrier
symbol duration12.8 µs + 0.8 µs guard interval = 13.6 µs
per spatial stream1,960 × 5 / 13.6 µs = 720.6 Mbit/s
two spatial streams (two antennas each side)1,441 Mbit/s

The reported rate matches exactly. With a better signal, the link would climb to MCS 11 — 1024-QAM, 2,402 Mbit/s with two streams — and Wi-Fi 7 adds 4096-QAM and 320 MHz channels. As with modems, the constellation is chosen for the noise.

How long the trip takes

Link rate is how fast bits leave; latency is how long they take to arrive. Five pings from this Mac to 1.1.1.1 (a public DNS server) took 63, 6.3, 6.5, 8.2 and 5.8 ms. The first one was slow — probably the Wi-Fi radio waking from power saving — and the others show a round trip of about 6 ms. A curl of https://example.com, run three times, reached TCP connection after 8–10 ms, finished the TLS handshake after 18–21 ms, and completed after 30–124 ms. Each of those stages is one or more round trips; bandwidth hardly matters for a page this small.

Light in fiber travels at about two thirds of its speed in vacuum, 200,000 km/s, so a 6 ms round trip means the server is at most about 600 km away along the cable, and in practice much closer, since routers and the Wi-Fi hop add delay. Bits have become cheap and plentiful; distance still costs time.

Takeaways

  • Channels pass limited frequencies, so bits are sent by modulating a carrier's amplitude, frequency or phase. Baud counts symbols per second; bits per second = baud × bits per symbol.
  • QAM chooses each symbol as a point in the (I, Q) plane: 16-QAM carries 4 bits per symbol, Gray-coded so a near miss costs one bit. The channel's signal-to-noise ratio sets how dense the constellation can be; Shannon's formula sets the ceiling.
  • Dial-up stopped at 33.6 kbit/s (56k only downstream) — history now. ADSL and cable used OFDM, many carriers each with its own QAM; fiber to the home is replacing both.
  • Line codes keep clock and balance on cables: Manchester for 10 Mbit/s Ethernet, PAM-5 on four pairs for gigabit, PAM4 for the fastest lanes.
  • An Ethernet frame carries MAC addresses, an EtherType, up to 1,500 bytes and a CRC-32, computed here: cbf43926 for "123456789". Modern Ethernet is switched and full duplex.
  • This Mac's Wi-Fi 6E link, 1,441 Mbit/s, is exactly 1,960 subcarriers × 5 bits / 13.6 µs × 2 streams; a round trip to 1.1.1.1 takes about 6 ms.

In this level

  1. 8.1Transistors as switches
  2. 8.2Building gates from CMOS
  3. 8.3From sand to chips
  4. 8.4Hard disks, SSDs and RAID
  5. 8.5Optical discs and tape
  6. 8.6Keyboards, displays, printers and cameras
  7. 8.7From modems to Ethernet: sending bits over a wire