Measure the uncertainty, or average information content, of a probability distribution, a set of counts or a piece of text, in bits, nats or dits.
H = −Σ p log₂ p
Shannon entropy is the average amount of information, or surprise, in the outcome of a random process. Measured in bits, it's the average number of yes/no questions needed to pin down the outcome.
A fair coin has entropy 1 bit: one question settles it. A coin that always lands heads has entropy 0, because there's nothing to learn. Entropy is highest when every outcome is equally likely and falls as the distribution becomes more predictable.
Claude Shannon defined it in 1948 to set the limit on data compression: no lossless code can average fewer bits per symbol than the source's entropy. The same quantity measures diversity in ecology and uncertainty in machine learning.
As given in Shannon (1948) and Cover & Thomas, Elements of Information Theory, chapter 2. See Sources.
b = 2 gives bits, b = e gives nats, b = 10 gives dits (hartleys).
The number of equally likely outcomes that would have the same entropy: an "effective number of choices".
Loading the die removes about 0.42 bits of uncertainty per roll. A cheat who knows the bias can, on average, guess outcomes as if the die had only 4.5 sides.
| Source | Entropy (bits) |
|---|---|
| Fair coin | 1 |
| Coin landing heads 90% of the time | 0.469 |
| Fair six-sided die | 2.585 |
| One random letter A–Z | 4.7 |
| One random digit 0–9 | 3.322 |
| Card drawn from a 52-card deck | 5.7 |
Bits with log base 2, nats with natural logs, and dits (or hartleys) with base 10. Switch with the chips above.
log K for K outcomes, reached when they are all equally likely.
No, not for a discrete distribution. The minimum is 0, when one outcome is certain.
Each character, including spaces and punctuation, is counted, and the entropy of those frequencies is reported per character.
The base raised to the entropy: an effective number of equally likely choices. It’s widely used to score language models.
Yes, mathematically, usually with natural logs. Ecologists call it H′ and apply it to species counts.
It’s the lower limit on the average number of bits per symbol any lossless code can achieve for that source.
Yes, within rounding. Use counts mode if you have raw frequencies.
Related Tools
Effect size measure.
Species diversity.
Categorical variability.
Intraclass correlation.
Smoothed trend line.
Percentage change.