Shannon Entropy Calculator
- Shannon entropy measures the average information in a message from a source: H = -sum of p x log2(p) over the possible outcomes, and it is measured in bits.
- The entered percentages sum to 100, so each is divided by that total to give the probabilities: 0.5, 0.5.
- The outcome terms are -0.5 log2 0.5 = 0.5000, -0.5 log2 0.5 = 0.5000.
- H = 1.00 bits. The maximum for 2 outcomes is log2(2) = 1.00 bits, so this source runs at 100.00% of its maximum, with a perplexity of 2.00 - the size of an equally likely alphabet with the same entropy.
This Shannon entropy calculator turns a set of outcome probabilities into a single measure of uncertainty in bits. Shannon entropy is H = -sum of p x log2(p) over all outcomes, measured in bits; it is the average information gained from one draw of the source. Enter your probabilities and the page reports the entropy directly, so you can compare sources at a glance. A fair coin (50/50) has entropy exactly 1.00 bit. Four equally likely outcomes (25% each) have entropy 2.00 bits, the maximum for four outcomes. A skewed 90/10 source has entropy only 0.47 bits, running at 46.90% of its 1-bit maximum, with a perplexity of 1.38. These examples show how sharply entropy falls as a source becomes predictable.
The method behind the result is the standard definition of information, not a shortcut or an approximation. Entropy was introduced by Claude Shannon in his 1948 paper A Mathematical Theory of Communication, the founding document of information theory, and the same formula remains the accepted way to measure uncertainty and average information in bits. This page shows the formula, step-by-step workings, worked examples and sources, so you can check every number yourself rather than trusting a black box. Whether you are a student learning information theory or a practitioner sizing up a data source, the calculator gives you the figure and the reasoning behind it.
Worked examples
A fair coin
Primary result: 1.00 bits. Full step-by-step working is shown with the result. (50 % · 50 % · 0 % · 0 % · 0 % · 0 %)
| Shannon entropy | 1.00 bits |
| Outcomes used | 2 |
| Maximum entropy | 1.00 bits |
| Efficiency | 100.00% |
| Perplexity | 2.00 |
Four equally likely outcomes
Primary result: 2.00 bits. Try it with your own numbers in the calculator above. (25 % · 25 % · 25 % · 25 % · 0 % · 0 %)
| Shannon entropy | 2.00 bits |
| Outcomes used | 4 |
| Maximum entropy | 2.00 bits |
| Efficiency | 100.00% |
| Perplexity | 4.00 |
A 90/10 source
Primary result: 0.47 bits. Every intermediate value is printed in the worked steps. (90 % · 10 % · 0 % · 0 % · 0 % · 0 %)
| Shannon entropy | 0.47 bits |
| Outcomes used | 2 |
| Maximum entropy | 1.00 bits |
| Efficiency | 46.90% |
| Perplexity | 1.38 |
What entropy measures
Shannon entropy is H = -sum of p x log2(p) over all outcomes, measured in bits. In plain terms, it is the average information gained from one draw of the source. That single number captures two ideas at once: how uncertain you are about what comes next, and how surprised you are when it arrives. A source that keeps you guessing carries more entropy than one whose next output you can already predict.
The fair coin is the cleanest example. With two outcomes at 50 percent each, the entropy is exactly 1.00 bit. One bit is the information in a single yes-or-no answer, which is why the coin is the natural yardstick. Four equally likely outcomes (25 percent each) have entropy 2.00 bits, the maximum for four outcomes, because you now need two yes-or-no answers to pin down the result. Equal probabilities always push entropy toward its ceiling for a given number of outcomes.
Real sources are rarely so balanced, and entropy drops when they are not. A skewed 90/10 source has entropy only 0.47 bits, running at 46.90% of its 1-bit maximum, with a perplexity of 1.38. Even though it still has two possible outcomes, one of them dominates so heavily that each draw tells you much less than a coin flip would. Prediction replaces surprise, and the average information per draw falls accordingly.
This is where compressibility comes in. Entropy sets the floor on how compactly a source's output can be described: high-entropy data resists compression because there is no pattern to exploit, while low-entropy data is full of predictability that a good coder can squeeze out. The skewed source, at 0.47 bits per draw, is far more compressible than the fair coin at 1.00 bit. A shannon entropy calculator makes this concrete: enter the outcome probabilities, and it returns the entropy in bits, the percentage of the maximum, and the perplexity, so you can see exactly how much uncertainty and compressibility a source carries.
The idea dates to Claude Shannon's 1948 paper A Mathematical Theory of Communication, the founding document of information theory. Shannon's insight was that information could be quantified and averaged over a source, turning a vague notion of surprise into a number you can compute, compare and use.
The formula, term by term
Shannon entropy is H = -sum of p x log2(p) over all outcomes, measured in bits; it is the average information gained from one draw of the source. The formula looks compact, but every piece of it does a specific job, so it is worth unpacking one term at a time. A shannon entropy calculator simply automates this arithmetic: it takes your outcome probabilities, computes each term, and adds them up.
Start with p. Each outcome's share of the total must be expressed as a probability between 0 and 1, so a source listed as 25% / 25% / 25% / 25% is first normalized to 0.25 / 0.25 / 0.25 / 0.25. Next comes log2(p), the base-2 logarithm, which is what puts the answer in bits. Then multiply the two: each outcome contributes -p x log2(p). The minus sign in front of the sum exists because probabilities are at most 1, so their logarithms are zero or negative; flipping the sign turns every contribution into a positive number. Finally, sum those contributions across all outcomes. Rare outcomes contribute little because their probability is small, and very common outcomes also contribute little because their logarithm is close to zero. The largest single contributions come from outcomes near the middle of the probability range.
Three worked examples show how the pieces combine. A fair coin has two outcomes at 0.50 each. Each contributes -0.50 x log2(0.50) = 0.50 bit, and adding the two gives exactly 1.00 bit. Four equally likely outcomes at 0.25 each contribute 0.50 bit apiece, so the total is 2.00 bits — the maximum for four outcomes. A skewed 90/10 source behaves quite differently: the 0.90 outcome contributes about 0.14 bit and the 0.10 outcome about 0.33 bit, for a total of only 0.47 bits. That is just 46.90% of its 1-bit maximum, with a perplexity of 1.38.
The contrast between the last two examples is the heart of the formula. Equal probabilities spread the information evenly and push entropy toward its ceiling; skew concentrates the probability on one outcome and pulls entropy down. The 90/10 source still has two possible outcomes, yet it carries less than half the information of a fair coin flip. That is why the term-by-term view matters: the sum reacts to the shape of the distribution, not just the count of outcomes.
The idea behind this formula is not new. Entropy was introduced by Claude Shannon in his 1948 paper A Mathematical Theory of Communication, the founding document of information theory. Running the numbers by hand is fine for two or four outcomes, but once a source has many outcomes the term-by-term sum grows tedious — which is exactly where a shannon entropy calculator earns its place.
Maximum entropy and efficiency
Every entropy value sits below a ceiling set by the number of possible outcomes. For k equally likely outcomes, that ceiling is log2(k) bits, and it is reached only when the probabilities are perfectly balanced. A fair coin, with two 50/50 outcomes, has entropy exactly 1.00 bit, which is log2(2). Four equally likely outcomes at 25% each have entropy 2.00 bits, the maximum for four outcomes. No arrangement of four probabilities can produce more than that. This is why the maximum is sometimes called the uniform ceiling: it describes the most uncertain source an alphabet of that size can be.
Real sources rarely sit at the ceiling. A skewed 90/10 source has entropy of only 0.47 bits. Against its 1-bit maximum, that is 46.90% efficiency — roughly half the uncertainty of a fair coin, even though both sources have two outcomes. A shannon entropy calculator makes this comparison easy: enter the probabilities, read the entropy in bits, and divide by log2(k) to see how close the source comes to its ceiling. The same 90/10 source also has a perplexity of 1.38, meaning its entropy is equivalent to that of a fair source with about 1.38 equally likely outcomes. Perplexity restates entropy as an equivalent alphabet size, so a value like 1.38 tells you the source behaves, in information terms, like something between a coin and a three-sided die.
Efficiency is a useful lens because it separates two different questions. The raw entropy tells you how many bits one draw delivers on average. The efficiency tells you how much of the available uncertainty the source actually uses. A source at 100% is maximally unpredictable for its alphabet. A source far below 100% is predictable: some outcomes are so common that each draw carries little surprise. The 90/10 case shows how quickly this happens — a modest imbalance cuts the information per draw by more than half.
The ceiling also clarifies why entropy depends on the outcome count. Adding more possible outcomes raises log2(k), so the same efficiency percentage means more absolute bits. A source at 50% efficiency with four outcomes carries 1.00 bit; at 50% with eight outcomes it carries 1.50 bits. The framework traces back to Claude Shannon, who introduced entropy in his 1948 paper A Mathematical Theory of Communication, the founding document of information theory. Maximum entropy, efficiency, and perplexity are all ways of reading the same underlying quantity from different angles.
- Maximum entropy for k outcomes is log2(k) bits, reached only when all outcomes are equally likely.
- A fair coin reaches its ceiling exactly: 1.00 bit.
- Four equally likely outcomes reach 2.00 bits, the maximum for four outcomes.
- A 90/10 source has 0.47 bits — 46.90% of its 1-bit maximum — with a perplexity of 1.38.
- Efficiency = actual entropy divided by log2(k); perplexity = 2^H, an equivalent alphabet size.
Where entropy is used
Shannon entropy, defined as H = -sum of p x log2(p) over all outcomes and measured in bits, is the average information gained from one draw of the source. That single definition, introduced by Claude Shannon in his 1948 paper A Mathematical Theory of Communication, the founding document of information theory, turned out to describe problems far beyond telegraphy. A shannon entropy calculator takes the probabilities you supply and returns that average, which is why the same number shows up in fields that seem to have nothing to do with one another.
In data compression, entropy sets a hard floor. If a source carries 2.00 bits per symbol on average, no lossless scheme can encode it in fewer bits per symbol on average. The classic illustrations make the floor concrete: a fair coin (50/50) has entropy exactly 1.00 bit, while four equally likely outcomes (25% each) have entropy 2.00 bits, the maximum for four outcomes. Skew helps: a 90/10 source has entropy only 0.47 bits, running at 46.90% of its 1-bit maximum, with a perplexity of 1.38. Predictable data is cheap to store; the calculator tells you how cheap before you write a line of code.
Password and passphrase strength is the same question in disguise. If each choice in a password is drawn from a known set of possibilities, the entropy of that draw estimates how much an attacker must learn. A passphrase built from many equally likely words scores higher than a short string of characters, because there are more outcomes and each is less likely. The fair-coin and four-outcome examples above show why: the flatter the distribution, the closer you get to the maximum, and the harder the guessing becomes.
In machine learning, cross-entropy loss measures how far a model's predicted distribution sits from the true one, and it is built directly on Shannon's formula. A confident model that assigns high probability to the wrong answer pays a large penalty; a hedged model pays less. The same arithmetic underlies perplexity, the 1.38 figure above being the exponential of 0.47 bits, which language models report as a readability-style score.
Ecologists and geneticists use entropy to measure diversity. A community where one species dominates resembles the 90/10 source and scores low; a community with many species at similar frequencies approaches the maximum, like four equally likely outcomes at 2.00 bits. Genetic variation across sites can be summarized the same way. In every case the interpretation is identical: entropy is the average surprise per draw, and a shannon entropy calculator gives you that number quickly.
- Data compression: entropy is the minimum average bits per symbol for lossless encoding.
- Password strength: flatter distributions of choices mean more entropy and more guessing for an attacker.
- Machine learning: cross-entropy loss and perplexity are built on the same formula.
- Ecology and genetics: entropy summarizes how evenly individuals or variants are distributed.
FAQs
What is Shannon entropy?
Shannon entropy is the average information, in bits, produced by a random source. It is written as H = -sum of p log2(p) over the source's outcomes. In plain terms, it measures how uncertain you are about which outcome will occur, so sources that are harder to predict have higher entropy.
How do you calculate Shannon entropy?
Convert the percentages to probabilities, multiply each probability by its own log2, negate the results, and add them together. A 50/50 source gives 1.00 bit, while a 90/10 source gives 0.47 bits. The uneven source is more predictable, so it carries less information per outcome.
What is the maximum entropy for 4 outcomes?
The maximum entropy for 4 outcomes is log2(4) = 2.00 bits. That value is reached only when all four outcomes are equally likely. Any imbalance among the four probabilities lowers the entropy below 2.00 bits, because the source becomes easier to predict.
What is perplexity?
Perplexity is 2 raised to the entropy. It gives the size of a uniform alphabet with the same uncertainty as your source. For example, the 90/10 source has perplexity 1.38, meaning its uncertainty matches a uniform source with about 1.38 equally likely outcomes.
Why is entropy measured in bits?
Entropy is measured in bits because log base 2 counts binary choices. One bit is the information in a single fair yes/no answer. Using base 2 makes the unit match how computers and communication systems encode decisions, so entropy values translate directly into binary digits.
Can entropy be zero?
Yes, entropy can be zero. A source that always produces the same outcome has zero entropy and carries no information, because there is no uncertainty about what will happen. Any source with more than one possible outcome has entropy above zero.