Shannon entropy calculator
Calculate uncertainty in bits for a discrete probability distribution. Your inputs stay on your device.
Set up your task
Starting local processing
Ready. Processing stays in this browser.
2 Your result
Your result updates in this browser. Check your input if the result looks unexpected.
How to use Shannon entropy calculator
Calculate uncertainty in bits for a discrete probability distribution. The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.
- Check the example inputs: Outcome probabilities.
- Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.
- Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.
Supported inputs and limits
Enter probabilities for up to 64 outcomes. Zeroes are allowed and the values must sum to one.
How it works
Shannon entropy is the expected information gained on observing an outcome of a discrete distribution. The information for an event with probability p is minus the base-two logarithm of p. Weighting those values by their probabilities and summing expresses the result in bits.
An outcome of zero probability contributes zero by the limiting definition. A certain outcome gives entropy zero. For a fixed number of outcomes the maximum is attained when they are equally likely. Comparing the actual result with that bound can help interpret when a source is predictable enough to compress.
Example
Run the pre-filled example. Its first result is “Entropy: 1.5 bits”.
- Outcome probabilities
- 0.5 0.25 0.25
Entropy: 1.5 bits Contributions: 0.5 0.5 0.5 Maximum for 3 equally likely outcomes: 1.5849625 bits
Questions about Shannon entropy calculator
Do the numbers need to be frequencies or probabilities?
Use probabilities. Divide every frequency by the total before entering it, and retain enough decimal precision for the list to sum to one.
Can entropy be a fraction of a bit?
Yes. It is an average over outcomes. A specific code still uses a whole number of bits for each codeword.
Enter 0.25 0.25 0.25 0.25.
The entropy is exactly two bits because there are four equally likely outcomes. Try 1 0 0 0 and compare.
Related tools
Last updated