Shannon Entropy and Classical Information Measures

Information theory begins with a deceptively simple question: how much can a message be squeezed before something is lost? Claude Shannon's 1948 answer is that the irreducible content of a source emitting symbols xx with probabilities p(x)p(x) is captured by a single number, the entropy H(X)=−∑xp(x)log⁡2p(x)H(X)=-\sum_x p(x)\log_2 p(x), measured in bits when the logarithm is base two. A symbol of probability pp carries surprisal −log⁡2p-\log_2 p bits — a certainty (p=1p=1) surprises us not at all, a one-in-a-million event carries about twenty bits — and H(X)H(X) is simply the expected surprisal. A maximally uncertain source, uniform over dd outcomes, has H=log⁡2dH=\log_2 d; a deterministic source has H=0H=0. What makes the entropy more than a convenient average is that it is forced. Shannon and later Khinchin showed it is the unique function, up to the choice of unit, obeying a short list of natural axioms — continuity in the probabilities, the rule that spreading probability over more equally likely outcomes always raises uncertainty, and a grouping rule under which a hierarchically generated choice decomposes additively. And it is operational: the source coding theorem promotes H(X)H(X) from an axiomatic curiosity to a hard physical limit, the fewest bits per symbol into which a long stream can be losslessly compressed, no fewer, guaranteed by the asymptotic equipartition property that concentrates almost all probability on roughly 2nH(X)2^{nH(X)} typical sequences. From this one number the whole algebra of classical information measures unfolds — joint entropy, conditional entropy, mutual information, and the relative entropy whose single inequality, D(p ∥ q)≥0D(p\,\|\,q)\ge0, is the engine behind nearly every bound in the subject. These are exactly the quantities that lift into quantum information theory when distributions become density operators and HH becomes the von Neumann entropy, so understanding the classical layer first makes crisp which features are universal and which are quantum signatures.

Key takeaways
  • The Shannon entropy H(X)=−∑xp(x)log⁡2p(x)H(X)=-\sum_x p(x)\log_2 p(x) measures the average uncertainty, in bits, of a discrete random variable — the expected surprisal −log⁡2p(x)-\log_2 p(x) of its outcomes.
  • It is the unique measure (up to a unit) obeying continuity, monotonicity under uniform spreading, and the grouping axiom — the Shannon–Khinchin characterization.
  • Source coding: H(X)H(X) is the minimum average bits per symbol to losslessly compress an i.i.d. source, and the direct classical ancestor of Schumacher quantum data compression.
  • Joint entropy, conditional entropy, mutual information I(X;Y)I(X;Y), and relative entropy D(p ∥ q)D(p\,\|\,q) assemble into the chain rules and the data-processing inequality that govern all of information theory.
  • Relative entropy D(p ∥ q)≥0D(p\,\|\,q)\ge0 (Gibbs' inequality) is the master nonnegativity from which subadditivity, I(X;Y)≥0I(X;Y)\ge0, and data processing all follow.
  • Every measure here has a quantum lift — H→S(ρ)H\to S(\rho), I→I(A;B)ρI\to I(A;B)_\rho, D→S(ρ ∥ σ)D\to S(\rho\,\|\,\sigma) — but the quantum versions add subtleties like negative conditional entropy.
  • Key idea: the surprisal of an event of probability pp is −log⁡2p-\log_2 p bits, the Shannon entropy is its average, and it equals the optimal compression rate of an i.i.d. source; every other classical information measure is a linear combination of entropies whose inequalities reduce to the nonnegativity of relative entropy.
The core insight

The surprisal of an event of probability pp is −log⁡2p-\log_2 p bits; the Shannon entropy is its average, H(X)=E[−log⁡2p(X)]H(X)=\mathbb{E}[-\log_2 p(X)], and it equals the optimal compression rate of an i.i.d. source. All other classical information measures are linear combinations of entropies, and their inequalities ultimately reduce to the nonnegativity of relative entropy.

Where this lives today

Shannon's bits are the working currency of the digital world and the launchpad of its quantum successor. Every general-purpose compressor — the entropy coders inside ZIP, PNG, JPEG, H.264, and modern neural codecs — is engineered to approach the source coding limit H(X)H(X) per symbol, and arithmetic and asymmetric-numeral-system coders get within fractions of a bit of it on real data. The noisy channel coding theorem, C=max⁡pXI(X;Y)C=\max_{p_X}I(X;Y), is the target that turbo codes, LDPC codes, and polar codes were designed to reach, and 5G and deep-space links now operate within a fraction of a decibel of the Shannon limit. Relative entropy is the loss function at the heart of machine learning — training a classifier by cross-entropy is minimizing D(p ∥ q)D(p\,\|\,q) between the data and the model — and it supplies the error exponents of hypothesis testing through Stein's lemma. The frontier is the quantum lift: replacing distributions by density operators sends H→S(ρ)H\to S(\rho), I→I(A;B)ρI\to I(A;B)_\rho, and D→S(ρ ∥ σ)D\to S(\rho\,\|\,\sigma), and the open problems there — the additivity of channel capacities, the exact rates for entanglement-assisted communication, the role of strong subadditivity in constraining many-body entanglement — are all posed in the language Shannon built, with the classical inequalities of this article as the constraints they must respect.

The physical picture

Think of entropy as the expected number of yes/no questions needed to pin down an outcome under the smartest questioning strategy. For a uniform distribution over eight symbols you always need 3=log⁡283=\log_2 8 questions; for a skewed source you can do better on average by asking about the likely symbols first — and the best any strategy can do is exactly H(X)H(X) questions per symbol, a limit that Huffman and arithmetic codes approach. The entropy is therefore not a description of a message but a property of the source that emits it: it is the average price, in bits, of resolving one draw. The first figure makes the shape of this price concrete for the simplest possible source, a single biased coin, where the whole story lives on one curve.

Figure
The binary entropy function H₂(p) = −p log₂ p − (1−p) log₂(1−p): a biased coin's uncertainty peaks at exactly 1 bit for the fair coin p = 0.5 and collapses to 0 at the certain outcomes; a coin with p = 0.9 carries only H₂(0.9) = 0.469 bit
Entropy of one biased coin — maximal at p = 0.5, zero at certainty 1.0 0.5 0 0 0.5 1.0 probability p entropy H₂(p) in bits H₂(0.5) = 1 bit H₂(0.9) = 0.469 bit certain coin: H = 0

The measures that describe pairs of variables are best seen as areas. Draw the uncertainty of XX as one disc and of YY as another; where they overlap is the information the two share, and the mutual information I(X;Y)I(X;Y) is exactly that overlap. The joint entropy H(X,Y)H(X,Y) is the total area of the union, the conditional entropy H(X∣Y)H(X\mid Y) is the crescent of XX that survives once YY is known, and the identity I(X;Y)=H(X)+H(Y)−H(X,Y)I(X;Y)=H(X)+H(Y)-H(X,Y) is just inclusion–exclusion for two sets. The second figure is that Venn diagram made quantitative — the picture is exact for classical variables and, as the article on quantum mutual information will show, only a heuristic once operators enter.

Figure
The information diagram for two variables: the two uncertainty discs H(X) and H(Y) overlap in the mutual information I(X;Y), the union is the joint entropy H(X,Y), and the crescents are the conditional entropies — encoding the exact relation I(X;Y) = H(X) + H(Y) − H(X,Y)
Information diagram — I(X;Y) is the overlap of two uncertainties H(X) H(Y) H(X|Y) H(Y|X) I(X;Y) overlap H(X,Y) = H(X) + H(Y) − I(X;Y) = union of both discs

Underneath both figures sits the reason a single number can be a hard limit at all: the asymptotic equipartition property, the law of large numbers for information. Over a long run of nn independent draws the sequences split sharply into a typical set of about 2nH(X)2^{nH(X)} members, each occurring with probability near 2−nH(X)2^{-nH(X)}, plus an exponentially negligible remainder. Compression is then nothing more than handing each typical sequence an index — and there are only 2nH(X)2^{nH(X)} of them, so nH(X)nH(X) bits suffice. Relative entropy measures the cost of getting the source wrong: build a code tuned to a model qq while the data actually follow pp, and you overspend by exactly D(p ∥ q)D(p\,\|\,q) bits per symbol.

The core equations

The definition is an expectation of surprisal. Each outcome xx carries −log⁡2p(x)-\log_2 p(x) bits of surprise — larger for rarer events — and the entropy averages this over the source, so it is small when a few symbols dominate and large when probability is spread evenly.

H(X)=−∑xp(x)log⁡2p(x)(1)H(X)=-\sum_{x}p(x)\log_2 p(x) \qquad (1)

where: XX — discrete random variable with alphabet X\mathcal{X}; p(x)p(x) — probability Pr⁡[X=x]\Pr[X=x], with ∑xp(x)=1\sum_x p(x)=1; −log⁡2p(x)-\log_2 p(x) — surprisal (self-information) of outcome xx, in bits; H(X)H(X) — expected surprisal E[−log⁡2p(X)]\mathbb{E}[-\log_2 p(X)]. Reading it: H(X)H(X) is the average number of bits an ideal code spends per symbol, and the convention 0log⁡20:=00\log_2 0:=0 (justified by lim⁡p→0+plog⁡2p=0\lim_{p\to0^+}p\log_2 p=0) lets zero-probability symbols drop out silently. The entropy is pinned between two extremes: it cannot be negative, and it cannot exceed the entropy of the uniform distribution on the same alphabet. Both bounds are sharp.

0≤H(X)≤log⁡2∣X∣(2)0 \le H(X) \le \log_2|\mathcal{X}| \qquad (2)

where: ∣X∣|\mathcal{X}| — the number of symbols carrying nonzero probability. The lower bound is attained by a deterministic source and the upper bound by the uniform one; the gap log⁡2∣X∣−H(X)\log_2|\mathcal{X}|-H(X) turns out to be itself a relative entropy, which is why it can never be negative. For a pair of variables the joint entropy is the entropy of the combined outcome, treating (X,Y)(X,Y) as one random variable over the product alphabet.

H(X,Y)=−∑x,yp(x,y)log⁡2p(x,y)(3)H(X,Y)=-\sum_{x,y}p(x,y)\log_2 p(x,y) \qquad (3)

where: p(x,y)p(x,y) — joint probability Pr⁡[X=x, Y=y]\Pr[X=x,\,Y=y]. It measures the total uncertainty in learning both variables at once, and reduces to H(X)+H(Y)H(X)+H(Y) exactly when XX and YY are independent. Conditional entropy is the uncertainty in XX that remains after YY is revealed, averaged over what YY might be. Two equivalent forms — an average of conditional entropies, and a difference of joint and marginal — coincide by the product rule.

H(X∣Y)=∑yp(y) H(X∣Y=y)=H(X,Y)−H(Y)(4)H(X\mid Y)=\sum_y p(y)\,H(X\mid Y{=}y)=H(X,Y)-H(Y) \qquad (4)

where: H(X∣Y=y)=−∑xp(x∣y)log⁡2p(x∣y)H(X\mid Y{=}y)=-\sum_x p(x\mid y)\log_2 p(x\mid y) — entropy of the conditional law given a specific yy; p(x∣y)p(x\mid y) — conditional probability Pr⁡[X=x∣Y=y]\Pr[X=x\mid Y=y]. Because it is a probability-weighted average of ordinary (nonnegative) entropies, the classical H(X∣Y)≥0H(X\mid Y)\ge0 always — a fact that fails quantumly and signals entanglement when it does. Mutual information is the reduction in uncertainty about XX that knowing YY buys — symmetrically, the information the two share. It has three faces: a combination of entropies, a difference of a marginal and a conditional, and a divergence.

I(X;Y)=H(X)+H(Y)−H(X,Y)=∑x,yp(x,y)log⁡2p(x,y)p(x) p(y)(5)I(X;Y)=H(X)+H(Y)-H(X,Y)=\sum_{x,y}p(x,y)\log_2\frac{p(x,y)}{p(x)\,p(y)} \qquad (5)

where: I(X;Y)I(X;Y) — shared information, equal to H(X)−H(X∣Y)=H(Y)−H(Y∣X)H(X)-H(X\mid Y)=H(Y)-H(Y\mid X). It is symmetric, nonnegative, and vanishes precisely when XX and YY are independent; it is the classical prototype of the quantum mutual information I(A;B)ρI(A;B)_\rho. Relative entropy — the Kullback–Leibler divergence — is the master quantity. It is a directed, asymmetric measure of how distinguishable a true distribution pp is from a reference qq, and it is the penalty paid for modelling pp by qq.

D(p ∥ q)=∑xp(x)log⁡2p(x)q(x) ≥ 0(6)D(p\,\|\,q)=\sum_x p(x)\log_2\frac{p(x)}{q(x)}\ \ge\ 0 \qquad (6)

where: q(x)q(x) — reference distribution; D=+∞D=+\infty if p(x)>0=q(x)p(x)>0=q(x) for some xx; the value is generally asymmetric, D(p ∥ q)≠D(q ∥ p)D(p\,\|\,q)\ne D(q\,\|\,p). Its nonnegativity (Gibbs' inequality, derived below) is the single fact from which the bounds on HH, the positivity of II, subadditivity, and data processing all descend. Two structural identities close the toolkit. The chain rule decomposes the entropy of many variables into a telescoping sum of conditionals, and the data-processing inequality forbids any post-processing from manufacturing information.

H(X1,…,Xn)=∑i=1nH(Xi∣X1,…,Xi−1)(7)H(X_1,\dots,X_n)=\sum_{i=1}^{n}H(X_i\mid X_1,\dots,X_{i-1}) \qquad (7)
X→Y→Z  ⇒  I(X;Z)≤I(X;Y)(8)X\to Y\to Z \;\Rightarrow\; I(X;Z)\le I(X;Y) \qquad (8)

where: X1,…,XnX_1,\dots,X_n — jointly distributed variables; X→Y→ZX\to Y\to Z — a Markov chain, meaning ZZ is conditionally independent of XX given YY. The chain rule is the additive backbone of every multivariate calculation; the data-processing inequality is the formal statement that you cannot learn more about XX by looking at a processed copy ZZ than by looking at YY itself.

Derivation ANonnegativity of relative entropy — Gibbs' inequality

The goal is to prove the one inequality that everything else in this article rests on: that the relative entropy D(p ∥ q)=∑xp(x)log⁡2[p(x)/q(x)]D(p\,\|\,q)=\sum_x p(x)\log_2[p(x)/q(x)] is never negative, and equals zero only when pp and qq are the same distribution. This is the classical parent of Klein's inequality for density operators, and once it is in hand the bounds on entropy, the positivity of mutual information, subadditivity, and the data-processing inequality all follow by short algebra rather than fresh analysis. The whole proof is the elementary logarithm bound ln⁡t≤t−1\ln t\le t-1 applied one symbol at a time.

Step 1. Convert bits to nats so the natural logarithm's calculus is available: D(p ∥ q)=1ln⁡2∑xp(x)ln⁡p(x)q(x)D(p\,\|\,q)=\frac{1}{\ln 2}\sum_x p(x)\ln\frac{p(x)}{q(x)}, since log⁡2=ln⁡/ln⁡2\log_2 = \ln/\ln 2. Why: the constant 1/ln⁡2>01/\ln 2>0 cannot change a sign, so proving D≥0D\ge0 in nats proves it in bits; and the bound we need is a fact about ln⁡\ln, not log⁡2\log_2.

Step 2. Flip the ratio and apply ln⁡t≤t−1\ln t\le t-1 (equality only at t=1t=1) with t=q(x)/p(x)t=q(x)/p(x):

−D=1ln⁡2∑xp(x)ln⁡q(x)p(x)≤1ln⁡2∑xp(x)(q(x)p(x)−1).-D=\frac{1}{\ln2}\sum_x p(x)\ln\frac{q(x)}{p(x)}\le\frac{1}{\ln2}\sum_x p(x)\Big(\frac{q(x)}{p(x)}-1\Big).

Why: the tangent-line bound ln⁡t≤t−1\ln t\le t-1 is the single piece of convexity that does all the work; summing it over the support of pp turns an entropy inequality into an arithmetic one.

Step 3. Collapse the right-hand side using normalization, ∑xq(x)≤1\sum_x q(x)\le 1 and ∑xp(x)=1\sum_x p(x)=1:

1ln⁡2(∑xq(x)−∑xp(x))=1ln⁡2(1−1)=0.\frac{1}{\ln2}\Big(\sum_x q(x)-\sum_x p(x)\Big)=\frac{1}{\ln2}(1-1)=0.

Hence −D≤0-D\le0, i.e. D≥0D\ge0. Equality forces q(x)/p(x)=1q(x)/p(x)=1 everywhere on the support, so p=qp=q. Why: the two probabilities each sum to one, so the linearized bound telescopes to exactly zero — the inequality is saturated only when the tangent touches, which is the equality condition of Step 2.

Go deeper · Derivation B · 1 minSubadditivity, positivity of mutual information, and data processing
Derivation BSubadditivity, positivity of mutual information, and data processing

The aim is to show that three of the most-used inequalities in the subject — that joint entropy cannot exceed the sum of the marginals, that mutual information is nonnegative, and that processing a variable cannot increase what it tells you — are all the same statement wearing different clothes, each a direct corollary of Gibbs' inequality proved above. The trick throughout is to recognize a mutual information as a relative entropy between a true joint law and a factorized reference, so that D≥0D\ge0 does the entire job.

Step 1. Rewrite mutual information as a divergence: I(X;Y)=∑x,yp(x,y)log⁡2p(x,y)p(x)p(y)=D(pXY ∥ pX⊗pY)≥0I(X;Y)=\sum_{x,y}p(x,y)\log_2\frac{p(x,y)}{p(x)p(y)}=D\big(p_{XY}\,\|\,p_X\otimes p_Y\big)\ge0, with equality iff p(x,y)=p(x)p(y)p(x,y)=p(x)p(y). Why: the product of marginals is the "if they were independent" reference, and Gibbs measures exactly how far the true joint law sits from it — so positivity of II is positivity of DD.

Step 2. Translate back to entropies. Since I(X;Y)=H(X)+H(Y)−H(X,Y)≥0I(X;Y)=H(X)+H(Y)-H(X,Y)\ge0, we get subadditivity directly:

H(X,Y)≤H(X)+H(Y),H(X,Y)\le H(X)+H(Y),

with equality iff XX and YY are independent. Why: subadditivity is just I≥0I\ge0 rearranged — combining two sources never needs more bits than describing them separately, and needs strictly fewer when they are correlated.

Step 3. For a Markov chain X→Y→ZX\to Y\to Z, the chain rule gives I(X;Y,Z)=I(X;Y)+I(X;Z∣Y)=I(X;Z)+I(X;Y∣Z)I(X;Y,Z)=I(X;Y)+I(X;Z\mid Y)=I(X;Z)+I(X;Y\mid Z). The Markov property makes I(X;Z∣Y)=0I(X;Z\mid Y)=0, and the conditional mutual information I(X;Y∣Z)≥0I(X;Y\mid Z)\ge0 (Gibbs again, conditioned on each zz), so I(X;Y)=I(X;Z)+I(X;Y∣Z)≥I(X;Z)I(X;Y)=I(X;Z)+I(X;Y\mid Z)\ge I(X;Z). Why: every conditional mutual information is an average of ordinary divergences and so nonnegative; dropping the nonnegative I(X;Y∣Z)I(X;Y\mid Z) leaves the data-processing inequality I(X;Z)≤I(X;Y)I(X;Z)\le I(X;Y). *Classical subadditivity is elementary — a direct corollary of D≥0D\ge0 — whereas the quantum strong subadditivity of Lieb and Ruskai is a far deeper theorem.*

Go deeper · Derivation C · 1 minSource coding — the typical set and the compression rate H(X)
Derivation CSource coding — the typical set and the compression rate H(X)

The goal is to turn the entropy from an axiomatic average into an operational limit by proving the asymptotic equipartition property: for a long i.i.d. source the sequences that actually occur are almost all "typical", they number at most 2n(H(X)+ϵ)2^{n(H(X)+\epsilon)}, and each carries nearly the same probability. Indexing this typical set is the whole of lossless compression, and it pins the achievable rate at H(X)H(X) bits per symbol — the classical result that Schumacher later lifted to qubits.

Step 1. Define the typical set by the empirical log-probability:

Aϵ(n)={xn: 2−n(H(X)+ϵ)≤p(xn)≤2−n(H(X)−ϵ)}.A_\epsilon^{(n)}=\Big\{x^n:\ 2^{-n(H(X)+\epsilon)}\le p(x^n)\le 2^{-n(H(X)-\epsilon)}\Big\}.

By the weak law of large numbers applied to −1nlog⁡2p(Xn)=1n∑i[−log⁡2p(Xi)]-\frac1n\log_2 p(X^n)=\frac1n\sum_i[-\log_2 p(X_i)], this sample mean converges in probability to E[−log⁡2p(X)]=H(X)\mathbb{E}[-\log_2 p(X)]=H(X), so Pr⁡[Aϵ(n)]→1\Pr[A_\epsilon^{(n)}]\to1. Why: surprisal is itself a random variable with mean H(X)H(X); the AEP is nothing but the law of large numbers for that variable, forcing almost all probability into the typical band.

Step 2. Bound the size using total probability. Each typical sequence has p(xn)≥2−n(H(X)+ϵ)p(x^n)\ge2^{-n(H(X)+\epsilon)}, and the typical set's probability cannot exceed one:

1 ≥ ∑xn∈Aϵ(n)p(xn) ≥ ∣Aϵ(n)∣ 2−n(H(X)+ϵ).1\ \ge\ \sum_{x^n\in A_\epsilon^{(n)}}p(x^n)\ \ge\ \big|A_\epsilon^{(n)}\big|\,2^{-n(H(X)+\epsilon)}.

Why: if every member weighs at least 2−n(H+ϵ)2^{-n(H+\epsilon)} and they collectively weigh at most one, there can be at most 2n(H+ϵ)2^{n(H+\epsilon)} of them — a counting argument, nothing more.

Step 3. Read off the count and the rate:

∣Aϵ(n)∣ ≤ 2n(H(X)+ϵ).\big|A_\epsilon^{(n)}\big|\ \le\ 2^{n(H(X)+\epsilon)}.

A fixed-length code assigning a distinct index to each typical sequence therefore needs at most n(H(X)+ϵ)n(H(X)+\epsilon) bits, i.e. H(X)+ϵH(X)+\epsilon bits per symbol, while the exponentially rare atypical sequences contribute negligibly to the average. Why: compression is just labelling the sequences that occur, and there are only about 2nH(X)2^{nH(X)} of them — the converse (that no code beats H(X)H(X)) uses the matching lower bound on the typical set's size.

Limiting cases

Special distributions expose the meaning and the extreme values of the entropy, and the divergence between them.

CaseResultMeaning
Deterministic sourcep(x0)=1⇒H(X)=0p(x_0)=1 \Rightarrow H(X)=0No uncertainty, no information; the minimum, using 0log⁡20:=00\log_2 0:=0 by continuity.
Uniform over dd outcomesp(x)=1/d⇒H(X)=log⁡2dp(x)=1/d \Rightarrow H(X)=\log_2 dMaximum entropy for a dd-valued variable; equals the bits needed to label dd items.
Fair binary sourceH2(1/2)=1H_2(1/2)=1 bitThe peak of the binary entropy curve; one clean bit of uncertainty per coin.
Independent variablesX⊥Y⇒H(X,Y)=H(X)+H(Y), I(X;Y)=0X\perp Y \Rightarrow H(X,Y)=H(X)+H(Y),\ I(X;Y)=0Entropy is additive over independent parts; mutual information detects all correlation.
q=pq=p (perfect model)D(p ∥ q)=0D(p\,\|\,q)=0The divergence vanishes only when the model matches the source exactly.

Worked examples

1 · A dyadic source, its entropy, and an optimal code (fully worked)

A source emits four symbols {a,b,c,d}\{a,b,c,d\} with probabilities {12,14,18,18}\{\tfrac12,\tfrac14,\tfrac18,\tfrac18\}. Find its entropy, exhibit a code that meets the entropy bound exactly, and compute the relative-entropy penalty of instead coding it as if it were uniform.

Step 1. Entropy from the definition. Each surprisal is −log⁡2p-\log_2 p: symbol aa carries −log⁡212=1-\log_2\tfrac12=1 bit, bb carries 22 bits, and c,dc,d each carry 33 bits. Averaging,

H(X)=12(1)+14(2)+18(3)+18(3)=0.5+0.5+0.375+0.375=1.75 bits.H(X)=\tfrac12(1)+\tfrac14(2)+\tfrac18(3)+\tfrac18(3)=0.5+0.5+0.375+0.375=\mathbf{1.75\ \text{bits}}.

Because every probability is a power of two (a dyadic source), the surprisals are whole numbers of bits.

Step 2. A code that hits the bound. Assign codewords of length equal to each surprisal — a→0a\to0, b→10b\to10, c→110c\to110, d→111d\to111 (a Huffman code). This prefix-free code has average length 12(1)+14(2)+18(3)+18(3)=1.75\tfrac12(1)+\tfrac14(2)+\tfrac18(3)+\tfrac18(3)=1.75 bits per symbol, equal to H(X)H(X) with no gap. Dyadic sources are exactly the case where an integer-length code achieves the entropy; for general sources Huffman coding lands within one bit and arithmetic coding closes the remainder asymptotically.

Step 3. The penalty for the wrong model. Suppose you instead used a flat code tuned to the uniform distribution q={14,14,14,14}q=\{\tfrac14,\tfrac14,\tfrac14,\tfrac14\} — two bits for every symbol. The overspend per symbol is the relative entropy:

D(p ∥ q)=12log⁡21/21/4+14log⁡21/41/4+2⋅18log⁡21/81/4=12(1)+0+2⋅18(−1)=0.25 bit.D(p\,\|\,q)=\tfrac12\log_2\tfrac{1/2}{1/4}+\tfrac14\log_2\tfrac{1/4}{1/4}+2\cdot\tfrac18\log_2\tfrac{1/8}{1/4}=\tfrac12(1)+0+2\cdot\tfrac18(-1)=\mathbf{0.25\ \text{bit}}.

Consistency check: the flat code costs exactly 22 bits/symbol, and indeed H(X)+D(p ∥ q)=1.75+0.25=2H(X)+D(p\,\|\,q)=1.75+0.25=2 bits. This also confirms the identity log⁡2∣X∣−H(X)=D(p ∥ u)\log_2|\mathcal{X}|-H(X)=D(p\,\|\,u), since log⁡24−1.75=0.25\log_2 4-1.75=0.25. Answers: H=1.75H=1.75 bits, an optimal code averages 1.751.75 bits/symbol, and the uniform-model penalty is 0.250.25 bit/symbol.

2 · Mutual information through a noisy channel

A uniformly random input bit X∈{0,1}X\in\{0,1\} passes through a binary symmetric channel that flips it with probability p=0.1p=0.1, producing YY. How much does observing YY tell you about XX?

Step 1. By symmetry the output YY is also uniform, so H(Y)=1H(Y)=1 bit. Given the input, the only remaining randomness is the flip, so H(Y∣X)=H2(p)=H2(0.1)H(Y\mid X)=H_2(p)=H_2(0.1).

Step 2. Evaluate the binary entropy of the noise: H2(0.1)=−0.1log⁡20.1−0.9log⁡20.9≈0.469 bitH_2(0.1)=-0.1\log_2 0.1-0.9\log_2 0.9\approx\mathbf{0.469\ \text{bit}} (the same value as H2(0.9)H_2(0.9) by symmetry).

Step 3. Mutual information is the output uncertainty minus the noise: I(X;Y)=H(Y)−H(Y∣X)=1−0.469=0.531 bitI(X;Y)=H(Y)-H(Y\mid X)=1-0.469=\mathbf{0.531\ \text{bit}}. Since the uniform input maximizes II for this channel, this is also the channel capacity C=1−H2(p)=0.531C=1-H_2(p)=0.531 bit per use — the most reliable information a 10%10\%-flip channel can carry. Answer: each use of the channel conveys I(X;Y)=0.531I(X;Y)=0.531 bit, and this equals its capacity.

Physics of the portrait

The classical information measures are the work of one decisive paper and a small circle around it — a wartime cryptanalyst who saw that "information" could be measured in bits, that a source has an irreducible rate, and that noise sets a hard but achievable ceiling on communication.

Origins · 1 minClaude Shannon and how this was discovered
CS
Claude Shannon
1916–2001 · founder of information theory

Claude Elwood Shannon was an American mathematician and electrical engineer whose 1948 paper A Mathematical Theory of Communication, published in the Bell System Technical Journal, created information theory nearly complete in a single stroke. As a graduate student at MIT he had already, in his 1937 master's thesis, shown that Boolean algebra could describe switching circuits — arguably the most consequential master's thesis ever written, and the logical foundation of digital design. Turning to communication during and after his wartime cryptography work at Bell Labs (where he interacted with Alan Turing), he isolated the quantity H=−∑plog⁡pH=-\sum p\log p, borrowed the name "entropy" on von Neumann's advice for its formal identity with the Boltzmann–Gibbs expression, and proved the two theorems that anchor the field: the source coding theorem, fixing the compression limit at HH, and the noisy channel coding theorem, fixing the reliable communication rate at the capacity C=max⁡pXI(X;Y)C=\max_{p_X}I(X;Y). He introduced mutual information, conditional entropy, the typical-set argument, and the very notion of the "bit" as the unit of information. Famously playful — he built a juggling unicycle, a mechanical mouse that solved mazes, and a machine whose only function was to switch itself off — Shannon gave the emerging digital and, later, quantum information sciences their common language: every quantum entropy, capacity, and coding theorem is a deliberate lift of a structure he first drew for classical bits.

History
1924
— Nyquist relates the rate of signalling to bandwidth
1928
— Hartley proposes the logarithm of the number of messages as a measure of information
1948
— Shannon publishes A Mathematical Theory of Communication, defining entropy, mutual information, and channel capacity
1951
— Kullback and Leibler introduce the directed divergence, the relative entropy
1957
— Khinchin gives the rigorous axiomatic characterization of the entropy
1961
— Renyi generalizes entropy and divergence to a one-parameter family

Going further

Texts. Nielsen and Chuang, Quantum Computation and Quantum Information, Ch. 11–12 · Cover and Thomas, Elements of Information Theory, Ch. 2–3 · Wilde, Quantum Information Theory, Ch. 10 · Preskill, Lecture Notes on Quantum Computation, Ch. 10 · Watrous, The Theory of Quantum Information, Ch. 5 · Shannon, A Mathematical Theory of Communication, Bell Syst. Tech. J. (1948) · Mermin, Quantum Computer Science, Ch. 5. Key numerical anchors: H2(0.5)=1H_2(0.5)=1 bit and H2(0.9)=H2(0.1)≈0.469H_2(0.9)=H_2(0.1)\approx0.469 bit by direct computation; the dyadic source {12,14,18,18}\{\tfrac12,\tfrac14,\tfrac18,\tfrac18\} has H=1.75H=1.75 bits with a Huffman code of average length 1.751.75, and D(p ∥ u)=0.25D(p\,\|\,u)=0.25 bit matching log⁡24−H=0.25\log_2 4-H=0.25; the binary symmetric channel with p=0.1p=0.1 has I=C=1−H2(0.1)=0.531I=C=1-H_2(0.1)=0.531 bit; the Gibbs inequality rests on ln⁡t≤t−1\ln t\le t-1 and the AEP set-size bound is ∣Aϵ(n)∣≤2n(H+ϵ)|A_\epsilon^{(n)}|\le2^{n(H+\epsilon)}.

Prerequisites. Probability theory (discrete random variables, joint and conditional distributions) · Convexity and Jensen's inequality · Logarithms and basic asymptotics. Leads to. Von Neumann Entropy · Quantum Relative Entropy · Quantum Conditional Entropy and Mutual Information · Schumacher Data Compression · Holevo Bound · Data-Processing Inequality.

Ask the tutor: Ask me to walk you through why H(X)H(X) is the exact compression limit — or to show, step by step, how every inequality here falls out of the single fact that relative entropy is nonnegative.

Why the logarithm — why is information measured on a log scale?

Because information should add for independent sources. If a source has MM equally likely messages and a second independent source has NN, the combined source has M×NM\times N joint messages, yet intuitively it carries the sum of the two informations, not the product. The only continuous function turning products into sums is the logarithm, so log⁡(MN)=log⁡M+log⁡N\log(MN)=\log M+\log N forces the log scale. Choosing base two makes the unit the bit — the information in one fair coin flip. Base ee gives nats and base ten gives dits; they differ only by a constant factor, since log⁡bx=log⁡2x/log⁡2b\log_b x=\log_2 x/\log_2 b. Shannon's grouping axiom is the precise statement that pins the logarithm down uniquely.

What is the difference between surprisal and entropy?

Surprisal is a property of a single outcome; entropy is a property of the whole source. The surprisal −log⁡2p(x)-\log_2 p(x) tells you how many bits of "surprise" the specific outcome xx delivers — a near-certain event surprises you barely at all, a rare event a great deal. The entropy H(X)=∑xp(x) [−log⁡2p(x)]H(X)=\sum_x p(x)\,[-\log_2 p(x)] is the expected surprisal, averaging over which outcome the source will actually produce. So a single low-probability symbol can carry twenty bits of surprisal, yet contribute little to the entropy if it almost never appears. When people say "XX has three bits of entropy" they mean the source averages three bits of surprise per draw, which is also the average codeword length of an ideal compressor.

Why is relative entropy asymmetric, and which order should I use?

Because the two arguments play different roles: D(p ∥ q)D(p\,\|\,q) is the expected log-likelihood ratio under the true distribution pp, weighting each term by p(x)p(x). Swapping to D(q ∥ p)D(q\,\|\,p) reweights by qq and asks a different question, so the two numbers generally differ — and one can be finite while the other is infinite if their supports disagree. The rule of thumb: put the truth (or the data distribution) first and the model second, D(data ∥ model)D(\text{data}\,\|\,\text{model}), because that is the quantity equal to the extra bits per symbol you pay for using the model — and it is the "forward KL" that maximum-likelihood training minimizes. The reverse order appears in variational inference for its own reasons, but "truth first" is the coding-theoretic default.

How is Shannon's entropy related to the thermodynamic entropy of physics?

They are the same functional, −∑plog⁡p-\sum p\log p, and the connection is not a coincidence — von Neumann reportedly suggested the name to Shannon precisely because the formula matched Boltzmann's and Gibbs'. Thermodynamic entropy (in units where Boltzmann's constant kB=1k_B=1 and the log is natural) is the Shannon entropy of the probability distribution over a system's microstates, so it counts the bits of missing information about which microstate the system occupies. Landauer's principle makes the link physical: erasing one bit of information necessarily dissipates at least kBTln⁡2k_B T\ln 2 of heat. The main difference is domain, not form — thermodynamics fixes the distribution by maximum entropy under energy constraints (giving the Boltzmann distribution), whereas information theory takes the distribution as given.

Can mutual information ever exceed the entropy of one of its variables?

No. Since I(X;Y)=H(X)−H(X∣Y)I(X;Y)=H(X)-H(X\mid Y) and the classical conditional entropy H(X∣Y)≥0H(X\mid Y)\ge0, mutual information is bounded by I(X;Y)≤H(X)I(X;Y)\le H(X), and symmetrically I(X;Y)≤H(Y)I(X;Y)\le H(Y), so I(X;Y)≤min⁡{H(X),H(Y)}I(X;Y)\le\min\{H(X),H(Y)\}. The overlap in the information diagram can never be larger than either disc. Equality I(X;Y)=H(X)I(X;Y)=H(X) happens exactly when YY determines XX (then H(X∣Y)=0H(X\mid Y)=0), meaning YY tells you everything about XX. This bound is one of the places the classical picture is cleaner than the quantum one: the quantum mutual information can reach 2min⁡{S(A),S(B)}2\min\{S(A),S(B)\} for entangled states, twice the classical ceiling, which is the information-theoretic fingerprint of superdense coding.

Does the source coding theorem apply to real files, which are not i.i.d.?

The clean H(X)H(X) rate assumes independent, identically distributed symbols, and real data — text, images, audio — are strongly correlated, so a symbol-by-symbol entropy overstates their true information content. The theorem still governs them through the entropy rate H(X)=lim⁡n1nH(X1,…,Xn)H(\mathcal{X})=\lim_n \tfrac1n H(X_1,\dots,X_n), which accounts for all the inter-symbol correlations and is the correct compression limit for a stationary source. Practical compressors exploit exactly this: they model context (predicting each symbol from its predecessors) to drive the effective per-symbol entropy far below the naive marginal value. This is why an English text file compresses to roughly one bit per character rather than the four-plus bits its letter frequencies alone would suggest — the redundancy lives in the correlations.

Where this leads