Shannon Entropy Calculator

Measure the average uncertainty of a probability distribution in bits.

Technology and NetUpdated 2026-11-192 min read
Shannon Entropy Calculator
Between 2 and 20 probabilities separated by commas. They must add to 1 within 0.01.
Shannon entropy
...
Maximum possible entropy...
Number of outcomes...
Entropy 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

  1. Enter the probabilities separated by commas.
  2. Confirm they add to 1 within a small tolerance.
  3. Read the entropy in bits as the main result.
  4. Compare with the maximum entropy for that number of outcomes.
  5. Try 0.5 and 0.5 to see exactly 1 bit.
  6. Try equal probabilities over four outcomes to see 2 bits.

Formula

H = - sum over i of p_i times log base 2 of p_i, with 0 log 0 taken as 0
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.

  1. Check the sum: 0.5 plus 0.25 plus 0.25 is 1.
  2. First term: minus 0.5 times log base 2 of 0.5 is 0.5.
  3. Second term: minus 0.25 times log base 2 of 0.25 is 0.5.
  4. Third term gives another 0.5.
  5. Add them to get 1.5 bits.
  6. The tool also reports maximum entropy log base 2 of 3, about 1.584963 bits.

Reference table

Entropy for sample distributions
ProbabilitiesEntropyMaximum entropy
0.5, 0.25, 0.251.500000 bits1.584963 bits
0.5, 0.51.000000 bits1.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

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.