Shannon Entropy Calculator
Measure the average uncertainty of a probability distribution in bits.
What it does
Shannon entropy measures the average uncertainty in a random variable. It is the expected value of the surprise of an outcome, where surprise is the logarithm of one over its probability.
This tool takes a list of probabilities and computes minus the sum of each probability times its base two logarithm. Terms with probability zero contribute nothing. The page opens with 0.5, 0.25 and 0.25, giving 1.5 bits.
A fair coin has two equally likely outcomes and entropy of exactly 1 bit. A coin that always lands heads has zero entropy because its outcome is known in advance.
For n equally likely outcomes the entropy is log base 2 of n, which is also the maximum possible value for that n. The ratio of actual to maximum entropy is sometimes called redundancy or efficiency.
The same formula appears in data compression, coding theory and statistical mechanics, where logarithms in a different base correspond to different units.
How to use
- Enter the probabilities separated by commas.
- Confirm they add to 1 within a small tolerance.
- Read the entropy in bits as the main result.
- Compare with the maximum entropy for that number of outcomes.
- Try 0.5 and 0.5 to see exactly 1 bit.
- Try equal probabilities over four outcomes to see 2 bits.
Formula
- p_i
- Probability of outcome i.
- H
- Entropy in bits when the logarithm is base 2.
- log base 2
- Logarithm to base 2, giving information in binary digits.
A term with p equal to 0 is omitted because the limit of p log p as p approaches zero is zero. Using the natural logarithm instead would give entropy in nats, differing only by a constant factor.
Worked example
Example: probabilities 0.5, 0.25, 0.25
The page opens with probabilities 0.5, 0.25 and 0.25.
- Check the sum: 0.5 plus 0.25 plus 0.25 is 1.
- First term: minus 0.5 times log base 2 of 0.5 is 0.5.
- Second term: minus 0.25 times log base 2 of 0.25 is 0.5.
- Third term gives another 0.5.
- Add them to get 1.5 bits.
- The tool also reports maximum entropy log base 2 of 3, about 1.584963 bits.
Reference table
| Probabilities | Entropy | Maximum entropy |
|---|---|---|
| 0.5, 0.25, 0.25 | 1.500000 bits | 1.584963 bits |
| 0.5, 0.5 | 1.000000 bits | 1.000000 bits |
Limits
- Accepts 2 to 20 probabilities.
- Probabilities must be between 0 and 1 and sum to 1 within 0.01.
- Uses base 2 logarithms, so results are in bits.
- Zero probabilities are allowed and contribute nothing.
Common mistakes
- Forgetting to normalise probabilities to sum to 1.
- Using log base 10 and calling the result bits.
- Counting zero probability terms as infinite surprise.
- Expecting entropy to increase when a distribution becomes more certain.
- Confusing entropy with the number of outcomes.
Try it yourself
Quick checks. Answers sit tucked under each question.
Entropy of 0.5 and 0.5?
Exactly 1 bit.
Entropy of 0.5, 0.25, 0.25?
1.5 bits.
What is the maximum entropy for three outcomes?
Log base 2 of 3, about 1.584963 bits.
Questions
What is Shannon entropy?
The expected information content or uncertainty of a random variable.
Why use log base 2?
It measures information in bits, the natural unit for binary communication.
Can entropy be negative?
No. Each term is nonnegative because probabilities are at most 1.
What distribution maximises entropy?
The uniform distribution over the available outcomes.
What if a probability is zero?
Its term contributes zero because the limit of p log p is zero.
Where is entropy used?
Data compression, coding, cryptography and statistical mechanics.
Sources
- University of Toronto, information theory lecture notes on entropy
- Stanford University, introduction to information theory
- MIT OpenCourseWare, Shannon's entropy theorem