Mathematics.

entropy and information

Shannon Entropy

Information Theory40 minDifficulty4 out of 10

Overview

Shannon entropy H(X) quantifies the average uncertainty or information content of a random variable X. For a discrete distribution over n outcomes with probabilities p₁, …, pₙ, it is defined as H(X) = -∑ pᵢ log pᵢ. Choosing log base 2 gives units of bits; natural log gives nats; log base 10 gives Hartleys (or dits). Entropy is maximized when all outcomes are equally likely and equals zero when the outcome is certain. It is the foundational quantity of information theory, underpinning lossless compression limits, channel capacity, and the thermodynamic analogy between statistical physics and communication.

Intuition

Entropy measures surprise on average. If you flip a fair coin you are maximally uncertain — either outcome is equally likely, so you gain 1 bit of information per flip. If the coin is biased 99:1, most flips are predictable (heads almost always) and the average information per flip is much less than 1 bit. Entropy captures this: uniform distributions are maximally entropic (maximum surprise); degenerate distributions (one outcome certain) have zero entropy (no surprise). Think of it as the average number of yes/no questions needed to identify the outcome of the random variable.

Formal Definition

Definition

For a discrete random variable X taking values x₁, …, xₙ with probabilities pᵢ = P(X = xᵢ), the Shannon entropy in bits is:

H(X)=i=1npilog2piH(X) = -\sum_{i=1}^{n} p_i \log_2 p_i
Shannon entropy (bits)
H(X)=i=1npilnpiH(X) = -\sum_{i=1}^{n} p_i \ln p_i
Shannon entropy (nats)
H(X)=E[log2p(X)]H(X) = \mathbb{E}\left[-\log_2 p(X)\right]
Entropy as expected surprise
0H(X)log2n0 \leq H(X) \leq \log_2 n
Bounds on entropy
H(X)=0    pk=1 for some kH(X) = 0 \iff p_k = 1 \text{ for some } k
Zero entropy iff deterministic

Notation

NotationMeaning
H(X)H(X)Shannon entropy of random variable X
H(p)H(\mathbf{p})Entropy of probability vector p
H(XY)H(X|Y)Conditional entropy of X given Y
H(X,Y)H(X,Y)Joint entropy of X and Y

Theorems

Theorem 1: Non-negativity and Maximum Entropy
ForanydiscreterandomvariableXwithnoutcomes,0H(X)log2n,withH(X)=0iffXisdeterministicandH(X)=log2niffXisuniformlydistributed.For any discrete random variable X with n outcomes, 0 \leq H(X) \leq \log_2 n, with H(X) = 0 iff X is deterministic and H(X) = \log_2 n iff X is uniformly distributed.
Theorem 2: Chain Rule for Entropy
H(X1,X2,,Xn)=i=1nH(XiX1,,Xi1)H(X_1, X_2, \ldots, X_n) = \sum_{i=1}^{n} H(X_i \mid X_1, \ldots, X_{i-1})
Theorem 3: Subadditivity of Entropy
H(X,Y)H(X)+H(Y),withequalityiffXandYareindependent.H(X, Y) \leq H(X) + H(Y), with equality iff X and Y are independent.

Worked Examples

  1. 1

    A fair coin has p(heads) = p(tails) = 1/2.

    p1=p2=12p_1 = p_2 = \tfrac{1}{2}
  2. 2

    Apply the entropy formula.

    H(X)=12log21212log212H(X) = -\tfrac{1}{2}\log_2\tfrac{1}{2} - \tfrac{1}{2}\log_2\tfrac{1}{2}
  3. 3

    Since log₂(1/2) = -1, each term contributes 1/2 × 1 = 1/2.

    H(X)=12(1)+12(1)=1 bitH(X) = \tfrac{1}{2}(1) + \tfrac{1}{2}(1) = 1 \text{ bit}

✓ Answer

H(X) = 1 bit — the maximum entropy for a two-outcome variable.

Practice Problems

Easyfill in blank

A loaded die shows face 6 with probability 1/2 and all other faces with probability 1/10 each. What is H(X) in bits (to 2 decimal places)?

Mediumproof writing

Prove that H(X) ≤ log₂ n for any discrete random variable with n outcomes, with equality iff X is uniform.

Common Mistakes

Common Mistake

Treating 0·log(0) as undefined and excluding those terms.

By convention, 0·log 0 = 0 (using the limit limₓ→₀ x log x = 0). Outcomes with probability 0 contribute 0 to entropy.

Common Mistake

Confusing entropy with variance — a high-variance distribution need not have high entropy.

Entropy depends only on the probability values, not the actual outcome values. Two distributions with the same probability vector have the same entropy regardless of their support.

Quiz

What is the entropy of a deterministic random variable (one outcome has probability 1)?
Which choice of base for the logarithm in H(X) = -∑ pᵢ log pᵢ gives entropy in nats?
For a fair coin, H(X) = 1 bit. What is H(X,Y) where X and Y are independent fair coin flips?

Historical Background

Claude Shannon introduced entropy in his landmark 1948 paper 'A Mathematical Theory of Communication,' published in the Bell System Technical Journal. Shannon borrowed the term from Ludwig Boltzmann's statistical mechanics entropy, observing a mathematical parallel between thermodynamic uncertainty and communication uncertainty. John von Neumann reportedly suggested the word 'entropy' to Shannon since 'no one knows what entropy really is.' Shannon's formulation unified disparate results in telegraphy, cryptography, and statistics into a single coherent theory.

  1. 1872

    Boltzmann introduces H-theorem and statistical entropy in thermodynamics.

    Ludwig Boltzmann

  2. 1948

    Shannon publishes 'A Mathematical Theory of Communication', defining entropy for discrete sources.

    Claude Shannon

  3. 1949

    Shannon and Weaver publish the book 'The Mathematical Theory of Communication'.

    Claude Shannon, Warren Weaver

  4. 1951

    Shannon proves the noiseless coding theorem, linking entropy to optimal compression rates.

    Claude Shannon

Summary

  • Shannon entropy H(X) = -∑ pᵢ log pᵢ measures average uncertainty in bits (log base 2), nats (natural log), or Hartleys (log base 10).
  • Entropy is non-negative, equals 0 for deterministic variables, and is maximized (log₂ n bits) for the uniform distribution over n outcomes.
  • The chain rule H(X,Y) = H(X) + H(Y|X) decomposes joint entropy; subadditivity H(X,Y) ≤ H(X)+H(Y) holds with equality iff X,Y are independent.
  • Shannon's source coding theorem states that the minimum average code length for lossless compression is H(X) bits per symbol.

References

  1. BookCover, T. and Thomas, J. (2006). Elements of Information Theory, 2nd ed. Wiley.