How do you calculate entropy for a complete discrete distribution?
Let X be a discrete random variable with finitely many possible outcomes x1 through xn. Each outcome has probability pi = P(X = xi). The probabilities are nonnegative and sum to one. Entropy depends on these probabilities; merely relabelling outcomes does not change it. For observed nonnegative counts with , substitute . The result describes the sample’s empirical distribution and is not automatically the exact source entropy or an unbiased estimate of it.[2][5]
The formula takes the expected information per outcome.
A completely predictable output has zero entropy. That does not mean it is unimportant. Entropy measures statistical unpredictability under the chosen model, not the usefulness, truth or semantic meaning of a message.
Why does a base-two logarithm give bits?
A rare outcome has greater information content than a common one; pi > 0.[1]
The logarithm matches the addition of independent information: independent probabilities multiply, while their negative logarithms add. The base determines the unit. Base 2 gives bits; the natural logarithm gives nats.
Additivity for independent events with positive probabilities.
Weight each information value by its probability and add all contributions.
An impossible outcome contributes zero to the average. Set the whole term to zero rather than evaluating log2(0).
Why uniform probabilities maximise entropy
For n possible outcomes, 0 ≤ H(X) ≤ log2 n. A certain outcome gives H = 0. The upper bound is reached exactly when all n outcomes have probability 1/n.[3]
Under a uniform distribution every term is equal; n terms cancel the factor 1/n.
The lower bound follows directly from the terms: for 0 < p ≤ 1, log2 p ≤ 0, so −p log2 p ≥ 0. For the upper bound, use concavity of the logarithm. Jensen’s inequality gives the following calculation for m positive probabilities.
The weights pi sum to one. Equal positive probabilities achieve equality in the first bound.
A fair binary source has maximum entropy
Free with a Quanta account. Your download stays ready after registration.
Three examples: distribution, weighting and side information
Three source outputs
- Given
- A source outputs A with probability , and B and C with probability each.
- Find
- Entropy and an example of a matching prefix-free binary code.
Approach: The specified source has three discrete outcomes. Base-two logarithms give information in bits; probability weighting yields mean information and permits comparison with a prefix-free code.
Check probabilities: .
Information values are 1 bit for A and 2 bits for B and C.
Add the weighted contributions.
Result: H = 1.5 bits per output. Code A → 0, B → 10, C → 11 has the same average length.
Check: No codeword is a prefix of another. Average length is ; each individual output still uses an integer number of bits.
An uneven yes/no output
- Given
- P(yes) = 0.8, P(no) = 0.2.
- Find
- Find average information and compare it with a fair binary source.
Approach: The two complementary outcome probabilities define a Bernoulli source. Binary entropy weights both information values; a fair source provides an independent comparison at maximum binary uncertainty.
Label yes as 1 and no as 0. Calculate a base-two logarithm for each outcome.
Do not take an unweighted average; multiply by 0.8 and 0.2.
Result: H ≈ 0.722 bits per output, below the maximum of 1 bit.
Check: An individual rare no contains more information but occurs less often. Swapping yes and no with their probabilities leaves H unchanged.
How much uncertainty does a clue remove?
- Given
- is uniform over four outcomes. Clue reliably tells whether lies in or .
- Find
- Find original entropy, conditional entropy and mutual information.
Approach: four outcomes are possible before the clue. Either clue leaves two equally probable outcomes.
Weight the remaining uncertainty for both clue values.
The mean reduction in uncertainty is mutual information.
Result: The clue provides of information, leaving of uncertainty about .
Check: is itself a fair bit and is determined by . Thus here, although the clue does not determine completely.
Entropy is not a universal file-size prediction
For lossless binary prefix codes of a discrete source, average codeword length is at least entropy. Suitable block coding of independent identically distributed outputs can approach H per output. Finite blocks, headers and communicating the model add overhead. Shannon–Hartley channel capacity instead concerns the achievable rate in a separate band-limited noisy-channel model; it is not another entropy formula for this source.[1]
Suppose a fair binary source independently produces 400 values. Their joint entropy is 400 bits. If one fair value is instead repeated 400 times, every position is individually fair, yet the whole sequence contains only 1 bit of random information. Dependence therefore changes the calculation fundamentally.
Individual entropies add directly only for independent outputs.
Five exercises with solutions
Calculate · Foundation
1. Eight outputs are equally likely. Find H.
Show hint
Use the uniform-distribution expression.
Learning goal: Calculate uniform entropy.
Show solution and calculation
Approach: .
H = log2 8 = 3 bits per output.
Calculate · Application
2. Probabilities are . Calculate H.
Show hint
Weight information values 1, 2, 3, 3.
Learning goal: Calculate weighted distribution entropy.
Show solution and calculation
Approach: .
H = 0.5 + 0.5 + 0.375 + 0.375 = 1.75 bits, below the four-outcome maximum of 2 bits.
Interpret · Application
3. One output has probability 1; all others have probability 0. What is the entropy?
Show hint
Use log2 1 = 0 and the zero-term convention.
Learning goal: Recognize zero entropy for a certain outcome.
Show solution and calculation
Approach: .
H = 0.
The output is certain; zero probabilities contribute nothing under the limiting convention.
Interpret · Application
A fair coin is tossed once. The source prints that result twice: HH or TT, each with probability one half. Find two-symbol block entropy and entropy per printed symbol. Is this equivalent to two independent tosses?
Show hint
Count possible blocks rather than doubling single-symbol entropy.
Learning goal: Account for dependence in block entropy.
Show solution and calculation
Approach: There are only two equally probable blocks, giving 1 bit per block and 0.5 bit per printed symbol.
Two independent tosses would produce four blocks and 2 bits.
Each symbol is marginally fair but the symbols are fully dependent.
Summing marginal entropies gives block entropy only under independence.
Error analysis · Application
A binary source outputs A with probability 0.9 and B with 0.1. Someone calls the information of rare B the average entropy. Compute both and explain the error; use base-two logarithms.
Show hint
Entropy also weights the common event.
Learning goal: Distinguish event information from its expectation.
Show solution and calculation
Approach: Rare B provides about 3.32193 bits of information.
The probability-weighted mean across both events is instead about 0.468996 bits per output.
Common A provides little information and occurs nine times as often.
Entropy cannot exceed the binary maximum of 1 bit, immediately exposing the claimed equality.
Avoid common calculation errors
- Divide percentages by 100 first; 80% corresponds to p = 0.8.
- Probabilities must describe a complete set of mutually exclusive outputs and sum to 1.
- Use on a calculator. Using ln alone gives nats.
- Weight every logarithm by its matching p and keep the minus sign.
- Sample frequencies are estimates, not automatically exact source probabilities.
Specify the complete discrete distribution and weight each information value by its probability. Base two gives bits. Entropy is an average; dependence, side information and actual coding require separate consideration.
Sources for this explanation
Quanta · Updated October 2, 2026
- MIT 6.02, Chapter 2: Information, Entropy, and the Motivation for Source Codes
- MIT 6.441 (2010), Lecture 1: Entropy and mutual information
- MIT 6.441 (2006), Lecture 2: Entropy properties
- MIT 6.441 (2006), Lecture 15: Differential entropy
- Liam Paninski (2003): Estimation of Entropy and Mutual Information
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 3 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An internal human subject review is documented for an earlier release of this page. That confirmation does not apply automatically to the revised explanation and new exercises.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Refined question headings and relevant paragraph links; added the full empirical-frequency substitution and a primary source on estimation limits. Preserved existing examples and exercises.
- Added two exercises; labelled all five by task type, difficulty and learning goal.
- Reviewed the learning sequence; added a third example, an original quantitative figure, symbolic exercise approaches and a short summary.
Cite this reference page
Quanta. Shannon entropy. Updated October 2, 2026. https://quanta-study.de/en/formula-sheet/shannon-entropie
When citing a specific scientific statement, also cite the specialist source linked to that statement.