How to use the shannon entropy calculator
- Paste or type the text.
- Choose whether to count characters or UTF-8 bytes.
- Read the entropy in bits per symbol, the number of symbols and how many are different.
- Use the table to see how often each symbol appears and what it contributes.
Formula
p(s) = count of symbol s / total symbols
Entropy H = - sum over all symbols of p(s) x log base 2 of p(s)
Ideal size = H x number of symbols / 8 bytes
The result treats each symbol as independent. It measures the spread of symbol frequencies and nothing about order or meaning.
A pangram
In "the quick brown fox jumps over the lazy dog" there are 43 symbols and 27 different ones, since the spaces count as a symbol and several letters repeat. The entropy is 4.3855 bits per character. At that rate the text could ideally be stored in 23.6 bytes, compared with 43 bytes as plain text.
A string of one repeated letter has an entropy of 0, because it is fully predictable. The string abcdabcdabcdabcd has four equally common symbols, so its entropy is exactly 2 bits per character, the most that four symbols can have.
What entropy tells you
Entropy measures how surprising each symbol is on average. A text with a few very common symbols is more predictable and has lower entropy. A text where every symbol is equally likely has the highest entropy for its alphabet, which is the base 2 logarithm of the number of different symbols. The figure sets a lower limit on how far a simple code can compress the text if it uses symbol counts alone.
Real compressors do better by also using patterns such as repeated words, so the ideal size here is not a limit for them. It is a limit only for a code that treats each symbol on its own.
Cautions
Short texts give rough numbers because the counts are small. Entropy of a password string is not the same as its strength, since strength depends on how it was chosen, not on the letters it happens to contain. The Password Strength Checker looks at that question. See the Text Byte Size Calculator for the size of text in different encodings, the Word Frequency Counter for counts of words, and the LZW Compression Stepper to watch a real compression method work.
Assumptions and limits
- Symbols are treated as independent, with probabilities taken from the text itself.
- In byte mode the text is encoded as UTF-8 first, so accented letters count as two or more bytes.
- The sample sentence is an example. Use your own text.
- Everything is calculated in your browser and nothing is uploaded.
Frequently asked questions
What is a bit per character?
It is the average number of yes or no answers needed to identify the next symbol, if you knew the symbol frequencies in advance.
Why is the ideal size smaller than the original?
Because common symbols could be given short codes. The figure assumes the best code that uses symbol frequencies alone.
Should I count characters or bytes?
Characters for text analysis. Bytes for files or data, where each byte value is a symbol and the maximum is 8 bits.
Does a higher number mean better randomness?
Only that symbols are spread more evenly. It does not prove the data is random or secure.