
Mathematics
Information Theory: From Bits to the Shannon Limit
A practical tour of information theory for engineers: entropy, source coding and the limits of compression, mutual information and cross-entropy, channel capacity, channel coding from Hamming (7,4) to LDPC, Shannon channel capacity and the Shannon–Hartley formula checked against real Wi-Fi rates, MIMO channel capacity with water-filling, and rate–distortion theory.
Overview
In 1948 Claude Shannon published A Mathematical Theory of Communication and answered two questions that sound like engineering folklore but turn out to have exact answers:
- How small can a message be made? Every source has an entropy, a number of bits per symbol below which no lossless compressor can go.
- How fast can data be sent through a noisy channel? Every channel has a capacity. Below it, errors can be made as rare as you like with the right code. Above it, they cannot.
Almost everything in a modern radio, a ZIP file or a language model’s training loop is an engineering approximation of those two limits. This post builds the ideas from the ground up, with a worked example in each section:
| Section | The question it answers |
|---|---|
| Entropy | How much uncertainty, in bits, does a source have? |
| Source Coding | How far can data be compressed without loss? |
| Mutual Information | How much does one signal tell you about another? |
| Channel Capacity | What is the highest reliable rate through a noisy channel? |
| Channel Coding | How do real codes get close to that rate? |
| Shannon Channel Capacity | What is the limit for a radio link with bandwidth and noise? |
| MIMO Channel Capacity | What do extra antennas buy? |
| Rate–Distortion Theory | How few bits are needed if some error is acceptable? |
The maths needs nothing beyond logarithms and probabilities. If you want the radio side first, see Wi-Fi Overview and MIMO.
Information Is Surprise
Shannon’s first move was to separate information from meaning. A message carries information because the receiver did not know it in advance. A rare event tells you more than a common one, so the information content of an outcome with probability is defined as
| Event | Probability | Information |
|---|---|---|
| A fair coin lands heads | 1/2 | 1 bit |
| A fair die shows 6 | 1/6 | 2.58 bits |
| One card drawn is the ace of spades | 1/52 | 5.70 bits |
| The sun rises tomorrow | ≈ 1 | ≈ 0 bits |
The logarithm is not arbitrary. It is the only function that makes information from independent events add up: two coin flips have probability and carry bits. The base only sets the unit: base 2 gives bits, base gives nats (1 nat ≈ 1.443 bits), which is what machine learning frameworks use internally.
Entropy
The entropy of a random variable is the information you expect to receive, averaged over all outcomes:
Entropy measures uncertainty. A fair die has bits; a loaded die that shows 6 half the time has less, because you can guess its outcome better.
For a variable with only two outcomes, probability and , entropy becomes the binary entropy function:

A coin that lands heads 90% of the time has bits per flip. The dashed curve, , will come back as the capacity of a noisy channel.
Properties worth knowing
| Property | Formula | Meaning |
|---|---|---|
| Bounds | Zero when one outcome is certain; maximum when all outcomes are equally likely | |
| Joint entropy | Uncertainty about the pair | |
| Conditional entropy | Uncertainty left in once is known | |
| Chain rule | Learn , then learn what is left of | |
| Conditioning helps | On average, knowing more never increases uncertainty | |
| Independence | Only when and are independent |
Why entropy is “the number of bits”: typical sequences
The deepest reason entropy matters is the asymptotic equipartition property (AEP). Draw independent symbols from a source with entropy . As grows, almost all the probability concentrates on about typical sequences, each with probability close to . Everything else is so unlikely it can be ignored.
Take 100 flips of the 90%-heads coin. There are possible sequences, but almost every sequence you will actually see has about 90 heads, and there are only about of those. Give each typical sequence a 47-bit index and you have compressed 100 flips into 47 bits. That is the source coding theorem in one paragraph, and the same counting argument proves the channel coding theorem later.
How much information is in English?
| Model of English | Entropy per letter |
|---|---|
| 26 letters, all equally likely | bits |
| Single-letter frequencies (e is common, z is rare) | about 4.1 bits |
| Using the previous few letters as context | about 2 to 3 bits |
| Shannon’s human-prediction experiments (long context) | about 0.6 to 1.3 bits |
Each row uses more knowledge of the language, and the uncertainty about the next letter falls. That gap between 4.7 bits and about 1 bit is the redundancy of English, and it is exactly what a compressor or a language model exploits.
A few lines of Python estimate the byte-level entropy of a file, counting each byte on its own (no context):
import math, sys
from collections import Counter
data = open(sys.argv[1], "rb").read()
counts = Counter(data)
n = len(data)
h = -sum(c / n * math.log2(c / n) for c in counts.values())
print(f"{h:.3f} bits/byte (max 8.000)")
A text file typically reports 4 to 5 bits per byte, a compiled binary 5 to 6.5, and a .zip, .jpg or encrypted file very close to 8.000. A value near 8 means the bytes already look random: there is no structure left for a compressor to find.
Source Coding
Source coding is lossless compression: represent the output of a source with as few bits as possible, so that it can be recovered exactly.
Prefix codes and the Kraft inequality
Each symbol gets a binary codeword. To decode a stream without separators, no codeword may be the prefix of another (a prefix code). Codeword lengths for a prefix code exist if and only if they satisfy the Kraft inequality:
Think of each codeword as claiming a share of a budget of 1: a 1-bit codeword uses half of all possible bit strings, a 3-bit codeword one eighth. Short codewords are expensive, so they should go to the symbols that occur most often. The ideal length is , which is exactly the information content of the symbol.
Huffman codes
David Huffman’s 1952 algorithm builds the optimal prefix code for known probabilities: repeatedly merge the two least likely symbols into one node, until one node remains, then read each symbol’s code off the path from the root.

For the five symbols above:
- Fixed-length code: 5 symbols need bits each.
- Huffman code: bits per symbol on average, 27% smaller. Kraft check: .
- Entropy: bits.
The Huffman code is within 0.08 bit of the entropy. That remaining gap exists because codeword lengths must be whole numbers of bits.
The source coding theorem
Shannon proved that entropy is a hard floor. For any uniquely decodable code with average length ,
where the upper bound is achieved by Huffman coding. Coding blocks of symbols together spreads that one wasted bit over symbols, so the average per symbol approaches as closely as you like.
| Method | How it approaches entropy | Used in |
|---|---|---|
| Huffman | Optimal whole-bit code per symbol | DEFLATE (ZIP, gzip, PNG), JPEG, MP3 |
| Arithmetic coding | Encodes a whole message as one number in , effectively fractional bits per symbol | H.264/H.265 (CABAC), JPEG 2000 |
| Asymmetric numeral systems (ANS) | Arithmetic-coding efficiency at Huffman speed | zstd, LZFSE, JPEG XL |
| Lempel–Ziv (LZ77, LZ78, LZW) | Learns repeated strings on the fly, with no prior model; approaches the entropy rate for long inputs | gzip, zstd, GIF |
Two consequences matter in practice:
- No compressor shrinks everything. There are files of bits but fewer than shorter ones, so any compressor that shrinks some inputs must grow others. Compression works only because real data is not random.
- Compression is modelling. A coder can only spend bits on a symbol if it knows . Better predictions mean fewer bits, which is why the best text compressors today are driven by neural language models.
Mutual Information
Mutual information measures how much knowing one variable reduces uncertainty about another:
The quantities fit together like areas in a diagram:

Equivalently, mutual information is the KL divergence (defined below) between the joint distribution and the product of the marginals:
It is symmetric, never negative, and zero exactly when and are independent.
Worked example: does the umbrella tell you the weather?
It rains on 30% of days. On rainy days a colleague carries an umbrella 80% of the time; on dry days, 10% of the time. How much does seeing the umbrella tell you about the weather?
| Umbrella | No umbrella | Total | |
|---|---|---|---|
| Rain | 0.24 | 0.06 | 0.30 |
| Dry | 0.07 | 0.63 | 0.70 |
| Total | 0.31 | 0.69 | 1 |
- Before looking: bits.
- After seeing an umbrella: , so the remaining uncertainty is bits.
- After seeing no umbrella: , leaving bits.
- On average: bits.
So bits: the umbrella removes about 40% of your uncertainty about the weather. A radio channel is the same picture with = what was sent and = what arrived.
Data processing inequality
If form a chain (for example, transmitted bits, received signal, decoded bits), then
Processing can only lose information. No amount of clever post-processing at a receiver recovers information that the channel destroyed, and every hard decision (rounding a soft value to 0 or 1) throws some away. That is why modern receivers pass soft information to the decoder.
KL divergence and cross-entropy
Suppose the true distribution is but your code (or model) assumes . The average number of bits you then spend is the cross-entropy:
The extra term is the Kullback–Leibler divergence:
It is the price, in bits per symbol, of believing when the truth is . It is zero only when , and it is not symmetric, so it is a divergence rather than a distance.
This is exactly the loss used to train a language model, as in the LLM study guide. At each position the model outputs a distribution over the next token, and the training loss is the cross-entropy against the token that actually came next. Since is fixed by the data, minimising cross-entropy is minimising the KL divergence between the model and the language. A loss of 2.2 nats per token is bits per token, and its exponential, the perplexity , means the model is as uncertain as a uniform choice among 9 tokens. A model with lower loss is literally a better compressor: arithmetic coding driven by its predictions would store the text in about that many bits per token.
Channel Capacity
A channel takes an input and produces an output according to transition probabilities . The channel is fixed by physics; the only thing the sender controls is the input distribution . The capacity is the most mutual information that any input distribution can get through:
Capacity is a property of the channel alone, not of any particular code or modulation.
Two textbook channels

- Binary symmetric channel (BSC): each bit is flipped with probability , and the receiver cannot tell which ones. This models a hard-decision demodulator in a noisy radio.
- Binary erasure channel (BEC): each bit either arrives correctly or is marked as lost, with probability . This models a packet network where a checksum discards damaged packets.
Watch both channels at work, and drag the slider to change the noise:
For the BSC the capacity follows in three lines:
whatever is sent, because the noise flips each bit with probability independently of the input. is at most 1 bit, and it reaches 1 when the input is uniform. So . The same reasoning gives .
| Channel | Capacity | At 10% damage |
|---|---|---|
| Noiseless, symbols | n/a | |
| Binary erasure | 0.90 bit per use | |
| Binary symmetric | 0.53 bit per use | |
| BSC with | 0 | output independent of input |
An error you know about (an erasure) is much cheaper than one you do not. For channels without a neat closed form, the Blahut–Arimoto algorithm computes capacity numerically by alternately optimising the input distribution and the posterior.
The noisy channel coding theorem
Shannon’s central result: for any rate there exist codes whose error probability goes to zero as the block length grows; for any , the error probability stays bounded away from zero, whatever the code.
The proof is the typical-sequence argument again. A block of channel outputs has about typical values, and each input codeword spreads into a “noise ball” of about of them. The number of codewords whose balls do not overlap, and can therefore be told apart, is about
which means up to bits per channel use, maximised to .
This was a shock. Before 1948, engineers assumed that reducing errors meant reducing the rate, all the way to zero. Shannon showed that a noisy channel has a fixed, positive rate at which communication is essentially perfect. The proof uses random codes and very long blocks, so it shows such codes exist without saying how to build or decode them. That is the job of channel coding.
Channel Coding
Channel coding adds structured redundancy so that the receiver can detect and correct errors. A code maps data bits to coded bits; its rate is .
Repetition: the naive approach
Send every bit three times and take a majority vote. On a BSC with , a decoded bit is wrong only if two or three copies flip:
The error rate drops from 10% to 2.8%, but the rate drops to 1/3. More repetitions push errors lower and the rate towards zero. Capacity says we should be able to send at 0.53 bit per use with errors as rare as we like, so repetition is far from optimal.
Hamming distance and linear codes
The Hamming distance between two codewords is the number of positions where they differ. If every pair of codewords is at least apart, the code can
- detect up to errors, and
- correct up to errors, by picking the nearest codeword.
Most practical codes are linear: the sum (XOR) of two codewords is another codeword. A linear code is defined by a parity-check matrix : a word is a codeword if and only if . For a received word , the syndrome depends only on the error pattern, not on which codeword was sent.
Hamming (7,4): correcting one error cheaply
Richard Hamming’s 1950 code protects 4 data bits with 3 parity bits, giving and . Its parity-check matrix has the binary numbers 1 to 7 as columns:
So a single error in position produces a syndrome equal to column , which is the binary number . The same code drawn as three parity circles:

In the example, data 1011 becomes codeword 0110011; noise flips position 6 to give 0110001. The syndrome is , binary 6, so the decoder flips bit 6 back. Hamming (7,4) is also a perfect code: its codewords, each with the 7 words one flip away, fill all possible words exactly.
| Code | Rate | Corrects | Block error rate at p = 0.01 |
|---|---|---|---|
| No coding (4 bits) | 1 | nothing | |
| Repetition ×3 (4 bits) | 0.33 | 1 error per bit | about 0.12% |
| Hamming (7,4) | 0.57 | 1 error per block | about 0.20% |
Hamming gets almost the reliability of triple repetition at 70% more throughput. The same syndrome idea is how ECC memory corrects single-bit errors (usually with an extended Hamming code over 64 data bits).
Modern codes: getting close to capacity
| Code family | Idea | Where you meet it |
|---|---|---|
| Convolutional + Viterbi | Each output depends on a sliding window of input bits; decode by the most likely path | Wi-Fi BCC, GSM, satellite links |
| Reed–Solomon | Works on bytes; corrects bursts | CDs, QR codes, DVB, RAID-6 |
| Turbo codes (1993) | Two simple encoders plus an interleaver, decoded iteratively | 3G and 4G LTE data |
| LDPC (Gallager 1962, rediscovered 1990s) | Sparse parity-check matrix, decoded by passing beliefs along a graph | Wi-Fi 4 onwards, 5G NR data, DVB-S2, 10GBASE-T |
| Polar codes (2009) | Split a channel into very good and very bad sub-channels; send data only on the good ones | 5G NR control channels |
Turbo and LDPC codes were the breakthrough: with long blocks and soft-decision iterative decoding, they operate within a fraction of a dB of the Shannon limit. The improvement is measured as coding gain, the reduction in needed for a target error rate. Uncoded BPSK needs about 9.6 dB for a bit error rate of ; QPSK with a long rate-1/2 LDPC code (the same 1 bit/s/Hz) needs about 1.5 dB, a gain of about 8 dB, or more than six times less transmit power. In Wi-Fi, LDPC is optional in 802.11n and 802.11ac but required in Wi-Fi 6 and Wi-Fi 7 for wide channels and the highest MCS, which is part of why 1024-QAM and 4096-QAM are usable at all.
Shannon Channel Capacity
The channels above were discrete. A radio link carries continuous signals with additive noise, and its capacity is the result most people mean by “Shannon’s limit”.
The Gaussian channel
Model each received sample as , where the noise is Gaussian with power and the transmitter is limited to average power . Two facts give the answer:
- Among all distributions with a given power, the Gaussian has the largest differential entropy, .
- , because once is known, the only uncertainty left in is the noise.
has power , so , with equality for a Gaussian input. Subtracting :
The Shannon–Hartley formula
A signal of bandwidth hertz can carry independent real samples per second (the Nyquist rate). Multiplying gives the Shannon–Hartley formula:
where is the signal-to-noise ratio as a linear ratio, not in dB. This one formula explains the main levers of every radio standard:
- Bandwidth gives linear gains. Doubling doubles , which is why Wi-Fi went from 20 MHz to 40, 80, 160 and now 320 MHz channels.
- Power gives logarithmic gains. At high SNR, each doubling of signal power (+3 dB) adds only one bit per second per hertz.
- SNR sets the modulation. Bits per symbol cannot exceed , so 1024-QAM (10 bits per symbol) needs an SNR of at least 30 dB in theory and more in practice.
Worked example: a 20 MHz Wi-Fi channel
At an SNR of 25 dB, , so
for one spatial stream. A real Wi-Fi 6 link at 25 dB runs around MCS 6 (64-QAM, rate 3/4) at 77 Mb/s, a bit under half the bound. Plotting every MCS against the Shannon curve shows the pattern:

The staircase follows the shape of the curve, about 4 dB per extra bit per hertz against Shannon’s 3 dB, but sits well below it. The gap is not wasted cleverness. It is:
- Overhead: pilot subcarriers, guard bands, the guard interval and preambles carry no user data.
- Coding: practical block lengths are a few thousand bits, not infinite, and real decoders are not ideal.
- Margin: the SNR thresholds include room for fading, phase noise and imperfect channel estimates, so links do not fall over at the first fluctuation.
The Wi-Fi Topology Visualizer on this site uses the same SNR-to-MCS table to predict link rates on a floor plan.
Power versus bandwidth: the Eb/N0 view
Engineers often compare schemes by the energy per bit relative to the noise density , because that removes the bandwidth from the comparison. With spectral efficiency bits per second per hertz, the SNR is , and the capacity condition becomes

| Spectral efficiency η | Minimum |
|---|---|
| → 0 (unlimited bandwidth) | dB |
| 1 bit/s/Hz | 0 dB |
| 2 bit/s/Hz | 1.76 dB |
| 4 bit/s/Hz | 5.74 dB |
| 6 bit/s/Hz | 10.2 dB |
Two regimes appear:
- Power-limited (η well below 1): extra bandwidth buys a lot of energy saving. Deep-space probes and low-power IoT links live here, with turbo and LDPC codes operating within 1 to 2 dB of the −1.59 dB floor. No code, modulation or antenna trick can send a bit with less energy than that relative to the noise.
- Bandwidth-limited (η above about 2): every extra bit/s/Hz costs a large step in energy. Wi-Fi, cable and fibre systems live here, using dense QAM and long codes.
MIMO Channel Capacity
With transmit and receive antennas, the received vector is
where is the matrix of complex gains between every pair of antennas. The question is how much the extra antennas add to capacity.
Parallel channels from the SVD
Any matrix has a singular value decomposition . If the transmitter precodes with and the receiver combines with , the MIMO channel splits into independent scalar channels
each with power gain , the eigenvalues of . Capacity is the sum of the Shannon capacities of these eigen-channels. With the total power split equally across the transmit antennas:
Worked example: a 2×2 link at 20 dB
Take a fixed real channel
whose eigenvalues are and . At SNR = 20 dB (100), each antenna gets half the power:
A single-antenna link with unit gain at the same SNR gives bit/s/Hz. The second eigen-channel is weaker, but it still adds 4 bits per hertz: about 56% more capacity from the same total power.
Capacity grows with the number of antennas
In a rich scattering environment, modelled as i.i.d. Rayleigh fading, has up to strong eigenvalues. Averaging the capacity over many random channels gives:

At high SNR the capacity behaves like
so each extra pair of antennas adds another full , roughly another stream’s worth of capacity. The slope is the multiplexing gain. Compare a single antenna, where doubling the power only adds one bit per hertz. That is the information-theoretic reason behind spatial streams in Wi-Fi and massive MIMO in 5G, covered from the radio side in MIMO.
Water-filling: when the transmitter knows the channel
If the transmitter knows (in Wi-Fi, from channel sounding with NDP frames before beamforming), it can do better than equal power. The optimal allocation is water-filling:
Picture each eigen-channel as a vessel whose floor is at height (high for weak channels), then pour the total power in like water until it reaches a common level . Strong channels get more power; channels whose floor is above the water level get none.

Water-filling matters most at low SNR, where power is scarce. For the 2×2 example above at 0 dB, equal power gives 1.06 bit/s/Hz, while putting all the power on the strong eigen-channel gives bit/s/Hz, 31% more. At 20 dB the two strategies differ by less than 0.01 bit/s/Hz, which is why equal power is a reasonable default at high SNR.
What limits MIMO in practice
- Correlation: antennas too close together, or a strong line-of-sight path, make the columns of similar. The small eigenvalues collapse and the extra streams disappear.
- Rank: a “keyhole” (for example, a single doorway between rooms) can make nearly rank one even with many antennas at each end.
- Channel knowledge: precoding needs accurate, fresh channel estimates. Sounding costs airtime and goes stale as people and devices move.
- Device limits: Wi-Fi 6 and Wi-Fi 7 define up to 8 spatial streams, but phones usually have 2 antennas, so a single client rarely uses more than 2 streams. Multi-user MIMO serves several clients at once to use the rest.
Rate–Distortion Theory
Images, audio and video do not need exact reconstruction. Rate–distortion theory is the lossy counterpart of source coding: given a distortion measure and an allowed average distortion , what is the fewest bits per sample needed?
The minimum is over all ways of producing the reconstruction from that keep the distortion within . falls as grows: at (for a discrete source) it equals the entropy , and it reaches zero when the distortion allowed is as large as just guessing.

Two closed forms
| Source | Distortion | |
|---|---|---|
| Binary, | Fraction of bits wrong (Hamming) | for |
| Gaussian, variance | Mean squared error | for |
- Binary example: for a fair binary source, accepting 10% bit errors needs only bits per source bit, almost half.
- Gaussian example: a sensor reading reconstructed to 30 dB signal-to-distortion ratio needs , so bits per sample.
Turn the Gaussian formula around and every extra bit cuts the distortion by a factor of 4, which is dB. That is the familiar “6 dB per bit” rule for ADCs: a 16-bit converter has about 96 dB of dynamic range.
Reverse water-filling and transform coding
For several independent Gaussian components with variances (for example, the DCT coefficients of an image block), the optimal bit allocation is reverse water-filling: choose a level and give each component distortion , with rate
Components with variance below get zero bits: they are simply dropped. That is what JPEG, AAC, H.264 and their successors do: transform the signal so that energy collects in a few components, spend bits on those, and quantise the rest to zero.
Source–channel separation
Shannon’s last big result ties everything together. A source can be sent over a channel and reconstructed with distortion if and only if
(per source sample, with the channel uses matched to the samples). And it can be done optimally in two separate steps: compress to bits with a source code, then protect those bits with a channel code at a rate below . This separation theorem is why the internet can treat a video codec and a Wi-Fi PHY as independent layers. It holds for long blocks; for very short delays or broadcast to receivers with different SNRs, joint source–channel designs can still win.
Where It Shows Up
| Field | Information theory idea |
|---|---|
| Wi-Fi and cellular | Shannon–Hartley sets the rate ceiling; LDPC and polar codes approach it; MIMO adds parallel streams; link adaptation picks the MCS from SNR |
| Networking | Erasure codes (Reed–Solomon, fountain codes) recover lost packets without retransmission |
| Storage | ECC memory, RAID-6 parity and SSD LDPC codes; DEFLATE and zstd compression |
| Media | Rate–distortion and transform coding in JPEG, AAC, H.264/H.265, AV1 |
| Machine learning | Cross-entropy loss, KL divergence in variational methods, perplexity, decision-tree information gain |
| Security | Entropy of passwords and keys; a perfect cipher (one-time pad) needs a key with as much entropy as the message |
Summary
- Entropy is average surprise, , and by the AEP it counts how many bits a source really needs.
- Source coding cannot beat entropy; Huffman, arithmetic, ANS and Lempel–Ziv approach it, and random data cannot be compressed.
- Mutual information measures what one variable reveals about another; processing never increases it, and cross-entropy = entropy + KL divergence is the loss behind language models.
- Channel capacity, , is the highest rate at which errors can be made arbitrarily rare: for a BSC, for a BEC.
- Channel coding closes the gap: Hamming showed the idea, and LDPC, turbo and polar codes now operate within a fraction of a dB of capacity.
- Shannon channel capacity, , scales linearly with bandwidth and logarithmically with power, with an absolute floor of dB; real Wi-Fi runs a few dB below the curve.
- MIMO channel capacity grows with : the channel splits into parallel eigen-channels, and water-filling puts power where it helps most.
- Rate–distortion theory gives the bits needed for a given quality, for a Gaussian, and the separation theorem lets compression and channel coding be designed independently.
Further Reading
- Claude E. Shannon, “A Mathematical Theory of Communication”, Bell System Technical Journal, 1948. Still readable, and the first half needs little background.
- Thomas M. Cover and Joy A. Thomas, Elements of Information Theory, 2nd edition. The standard textbook, covering every section of this post.
- David J. C. MacKay, Information Theory, Inference, and Learning Algorithms. Free to read online from the author’s site, with excellent chapters on modern codes.
- David Tse and Pramod Viswanath, Fundamentals of Wireless Communication. Capacity of fading and MIMO channels from an engineer’s point of view.
- Emre Telatar, “Capacity of Multi-antenna Gaussian Channels”, European Transactions on Telecommunications, 1999. The paper behind the MIMO capacity formula.
- Tom Richardson and Rüdiger Urbanke, Modern Coding Theory. The reference for LDPC codes and iterative decoding.