Shannon Entropy Calculator
Measure the average information, or uncertainty, of a source. Paste text, a list of values, raw counts or a probability distribution and get the Shannon entropy in bits, nats or hartleys, plus maximum entropy, efficiency, perplexity and a full symbol frequency table with the formula worked out.
Last updated:
Each character (or word) is a symbol; its probability is how often it appears.
Decimals, fractions (1/4) or percentages (25%), separated by commas, spaces or new lines. Optional labels: A: 0.5
Raw tallies such as 10, 5, 5, or one 'label: count' per line.
Values separated by commas, semicolons, tabs or new lines (or spaces if there is no other separator). Identical values are counted together.
How to use the Shannon Entropy Calculator
- Pick the input type: text, probabilities, counts or a data list.
- Enter your data: paste text, or type values separated by commas or new lines (labels like
A: 0.5are optional). - Choose the unit: bits for computing and compression, nats for math and physics, hartleys for base-10 work.
- Press Calculate entropy (results also update as you type).
- Read the table: see each symbol's probability, self-information and share of the total entropy, then copy the results or download the CSV.
The Shannon entropy formula
For a source with outcomes whose probabilities are p1, p2, …, pn (adding up to 1), the Shannon entropy is
H = −Σ pi · logb(pi)
The base b sets the unit: b = 2 gives bits, b = e gives nats and b = 10 gives hartleys. Each term −p · log p is a symbol's contribution; the quantity −log p alone is its self-information or "surprise": a symbol that appears half the time carries 1 bit, one that appears 1/8 of the time carries 3 bits. Outcomes with probability 0 are skipped, because p · log p tends to 0 as p tends to 0.
When you start from counts (or from a text or data list), each probability is simply pi = counti ÷ total. This is the "plug-in" estimate; with small samples it tends to slightly underestimate the entropy of the underlying source.
Reference values
| Source | Distribution | Entropy (bits) | Entropy (nats) |
|---|---|---|---|
| Certain outcome | 1 | 0 | 0 |
| Biased coin | 0.9 / 0.1 | 0.469 | 0.325 |
| Fair coin | 0.5 / 0.5 | 1 | 0.693 |
| Four outcomes | 1/2, 1/4, 1/8, 1/8 | 1.75 | 1.213 |
| DNA base, all equal | 4 × 1/4 | 2 | 1.386 |
| Fair six-sided die | 6 × 1/6 | 2.585 | 1.792 |
| Random letter A–Z | 26 × 1/26 | 4.700 | 3.258 |
| Random digit 0–9 | 10 × 1/10 | 3.322 | 2.303 |
| Random byte | 256 × 1/256 | 8 | 5.545 |
Tips for reading the results
- Compare with the maximum. Entropy alone depends on how many symbols there are; normalized entropy (H ÷ log n) lets you compare a 4-symbol and a 20-symbol distribution on the same 0–1 scale.
- Characters or words? Character entropy of ordinary English text is usually around 4 to 4.5 bits per character when counted this way; word-level entropy is higher per symbol because the vocabulary is much larger.
- Case and spaces matter. Treating "A" and "a" as different symbols, or counting spaces, changes the distribution. Choose the option that matches what you want to measure.
- Ecology and diversity. The Shannon diversity index H′ used for species counts is the same formula with natural logs, so pick nats and enter the counts per species. Evenness (Pielou's J) equals the normalized entropy.
- Total information. Entropy per symbol × number of symbols gives the order-0 information content, a lower bound for coding each symbol independently.
Frequently asked questions
What is Shannon entropy?
Shannon entropy, introduced by Claude Shannon in 1948, is the average amount of information produced by a random source. For outcomes with probabilities p1 … pn it is H = −Σ pi log(pi). It is highest when all outcomes are equally likely and zero when one outcome is certain.
What is the difference between bits, nats and hartleys?
They are the same quantity measured with a different logarithm base: base 2 gives bits, base e (natural log) gives nats, and base 10 gives hartleys (also called dits or bans). 1 nat ≈ 1.4427 bits and 1 hartley ≈ 3.3219 bits.
How is the entropy of a string calculated?
Each distinct character (or word) is treated as a symbol. Its probability is its count divided by the total number of symbols, and those probabilities go into H = −Σ p log₂ p. For example, "hello world" has 8 distinct characters among 11 and an entropy of about 2.845 bits per character.
What is the maximum possible entropy?
With n possible outcomes, entropy is largest when every outcome has probability 1/n, giving Hmax = log(n). A fair coin has 1 bit, a fair six-sided die log₂ 6 ≈ 2.585 bits, and 256 equally likely byte values give 8 bits.
What do normalized entropy and perplexity mean?
Normalized entropy (efficiency) is H divided by Hmax, a 0 to 1 score of how evenly spread the distribution is; redundancy is 1 minus that. Perplexity is 2 raised to the entropy in bits, the number of equally likely choices that would have the same uncertainty.
Does the entropy of a text tell me how well it compresses?
It gives the order-0 limit: the fewest bits per symbol an ideal code could use if each symbol were coded independently with these frequencies. Real compressors such as ZIP also exploit repeated patterns and context, so they can do better on long text, while very short inputs carry overhead.
Is character entropy the same as password strength?
No. The entropy of a single string's own character frequencies is not the same as password entropy, which depends on how the password was chosen (the size of the pool and the number of random picks). Use it as a rough indicator of variety only.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.