Writing / Information Theory
A Complete Guide to Shannon Information Theory
From surprisal, entropy, and mutual information to compression limits, channel capacity, coding theorems, and modern machine learning.
Shannon information theory does not ask what a message means. It asks:
In the presence of uncertainty, how can information be measured, and how quickly can it be compressed or transmitted reliably?
Claude Shannon's 1948 paper, A Mathematical Theory of Communication, gave communication, compression, noise, and coding a common mathematical framework.
1. The decisive abstraction
A communication system can be represented as:
For a text message, the source is the text, the encoder turns it into bytes, packets, and physical signals, the channel is the network, noise includes loss and bit flips, and the decoder reconstructs the message.
Shannon deliberately sets meaning aside. The mathematical questions are:
- How uncertain is the receiver before the message arrives?
- How much uncertainty disappears after it arrives?
- What is the minimum number of bits needed to represent it?
- In a noisy channel, how quickly can it be transmitted reliably?
The central idea is that information is not the symbol itself; it is the uncertainty removed by observing the symbol.
2. Surprisal: unlikely events carry more information
For an event with probability , its self-information, or surprisal, is:
The unit is the bit. An event with probability 1 carries zero new information. One outcome of a fair coin carries:
An event with probability carries about bits.
The logarithm is important because independent probabilities multiply while information should add. If and are independent:
and therefore:
3. Entropy: average information produced by a source
Taking the expectation of surprisal gives entropy:
Entropy can be read as average uncertainty, average surprise, average information, or the lower bound on the average number of bits needed by an ideal code.
A fair coin has entropy 1 bit. For a heavily biased coin with and :
The output still takes one of two values, but it is highly predictable. Over long sequences it can be represented using far less than one bit per toss.
For possible outcomes, entropy is maximized by the uniform distribution:
Entropy is therefore not a strict synonym for disorder. It is uncertainty under a probability distribution.
4. The source coding theorem
How far can a random source be compressed? Its average code length cannot remain below , but for sufficiently long sequences it can be made arbitrarily close to .
Suppose and . A direct one-bit code assigns one bit to every character, but the source entropy is:
The theoretical average is about bits per symbol because only a comparatively small set of typical sequences carries most of the probability mass.
Compression does not mean discarding information. Lossless compression exploits non-uniformity and redundancy. Huffman coding, arithmetic coding, Lempel-Ziv, ZIP, and learned compressors all give shorter representations to more probable events.
This connects directly to language models. If a model assigns probability to the true token, its ideal code length is . Cross-entropy can therefore be interpreted as the average number of bits needed to encode data using the model.
5. Joint and conditional entropy
The joint entropy of and is:
It obeys the chain rule:
First describe , then describe the uncertainty still left in once is known. If , then . If and are independent, then .
6. Mutual information
Mutual information measures how much observing one variable reduces uncertainty about another:
Equivalently:
If and are independent, . If , then . A noisy copy lies between those cases.
Unlike correlation, mutual information is not limited to linear dependence. For example, if and is symmetric around zero, linear correlation may vanish even though is fully determined by .
7. KL divergence and cross-entropy
The Kullback-Leibler divergence is:
It is the extra coding cost incurred when data really follow but are encoded using . It is non-negative and equals zero only when the distributions agree, but it is not a true distance: it is asymmetric and does not generally satisfy the triangle inequality.
Cross-entropy is:
and:
When the data distribution is fixed, minimizing cross-entropy is equivalent to minimizing . This is why cross-entropy appears throughout classification and language modeling.
8. Noise and the channel model
Now consider:
Because of noise, the received may differ from the transmitted . In a binary symmetric channel, each bit flips with probability :
Can communication still approach zero error? Shannon's answer is yes, provided the transmission rate stays below the channel capacity.
9. Channel capacity
Channel capacity is:
It is the largest amount of information that can be transmitted reliably per channel use. The maximization over input distributions matters because different input distributions may use the channel with different efficiency.
For a binary symmetric channel:
where:
At , capacity is 1 bit per use. At , output is independent of input and capacity is zero. At , every bit flips deterministically and capacity returns to 1: the receiver can simply invert every bit.
10. The noisy-channel coding theorem
Let be channel capacity and the communication rate.
- If , codes exist whose error probability approaches zero as block length grows.
- If , no code can make communication arbitrarily reliable.
Noise does not make reliable communication impossible. It creates a rate limit.
Reliability comes from structured redundancy. Repetition codes show the basic idea, while Hamming, Reed-Solomon, Turbo, LDPC, and Polar codes achieve far better efficiency. Shannon did not construct the best code; he proved that good codes must exist and that a hard limit separates the possible from the impossible.
11. Source coding and channel coding point in opposite directions
Source coding removes predictable redundancy:
Channel coding adds structured redundancy for recovery:
A complete system often looks like:
The two operations are not contradictory: one removes redundancy that carries no new source information, while the other adds redundancy designed to reveal transmission errors.
12. Source-channel separation
If a source has entropy rate and a channel has capacity , reliable communication is possible in principle when:
Optimal compression and optimal channel coding may be designed separately. This separation is one foundation of modular digital communication.
Finite block lengths, strict latency limits, and semantic communication can make joint source-channel methods preferable in practice, but they do not erase the asymptotic theorem.
13. Typical sets
Take independent samples from . Most probability mass concentrates in a typical set containing roughly:
sequences, each with probability about:
The full space may contain sequences, but only about are needed to cover almost all probability. Distinguishing them takes roughly bits. This is the intuition behind entropy as the compression limit.
14. Information theory is not a theory of meaning
Two sentences can have similar Shannon information because they have similar probability and symbol structure, even if one is trivial and the other is existentially important.
Shannon information does not measure truth, meaning, value, importance, or human understanding. It measures the statistical uncertainty removed by a message under a chosen probability model.
That limitation is also the source of the theory's generality: once semantics are excluded, the same mathematics can describe text, radio signals, storage, genomes, and model predictions.
15. Connections to machine learning
Cross-entropy and maximum likelihood
The common supervised loss:
is the code length assigned to the true label by the model. Maximizing log likelihood is equivalently minimizing the encoded length of the observations under the model.
Language models and perplexity
For average token cross-entropy:
perplexity is:
If , then , roughly the uncertainty of choosing among eight equally likely candidates at each position.
Representation learning
The information bottleneck suggests keeping information about the target while discarding irrelevant detail:
The expression is conceptually useful, but mutual information in deterministic networks and continuous spaces can be difficult or ill-defined to estimate. It should not be applied too literally.
Contrastive and generative learning
InfoNCE is often interpreted through a lower bound on mutual information, although contrastive learning cannot be reduced to “maximize mutual information” alone.
The variational autoencoder objective contains:
The KL term regulates how far the latent distribution moves from its prior. Similar ideas of likelihood, entropy, and coding run through diffusion models, flow models, and language models.
16. Information depends on the observer's model
The quantity depends on the probability model used to assign . A weather event may surprise someone who knows nothing about the climate and be entirely expected to someone with a precise forecast.
Information is not solely an intrinsic property of the message. It is defined relative to a model.
This motivates anomaly scores such as , but also explains likelihood paradoxes: deep generative models can assign high likelihood to out-of-distribution inputs because likelihood reflects low-level statistics, not necessarily semantic normality.
17. What made Shannon's theory revolutionary
Three consequences matter beyond the entropy formula:
- Information can be separated from its physical carrier. Text, sound, images, and video can all become bits.
- Noise does not prevent reliable communication. Coding can drive logical error rates arbitrarily low below capacity.
- Engineering has provable limits. Compression and communication have boundaries that no clever algorithm can cross.
Communication became a mathematical discipline with explicit limits rather than only an empirical craft.
18. The core quantities at a glance
| Quantity | Formula | Interpretation |
|---|---|---|
| Surprisal | How unexpected one event is | |
| Entropy | Average uncertainty in a random variable | |
| Conditional entropy | Uncertainty left in after observing | |
| Mutual information | Uncertainty about removed by | |
| KL divergence | Extra coding cost from using the wrong model | |
| Channel capacity | Maximum reliable information per channel use |
19. Two conclusions to keep
The compression limit is:
The communication limit is:
Entropy describes how quickly a source produces information. Capacity describes how quickly a channel can carry it. When production stays below transport capacity, reliable communication is possible.