Skip to content
🛠️ToolsShed

Text Entropy Calculator

Calculate Shannon entropy and bits-per-character of any text.

Start typing to calculate entropy.

About this tool

Shannon entropy is a mathematical measure of the average information content or randomness in a message, calculated in bits. When you paste text into this calculator, it computes the entropy based on the frequency distribution of characters, revealing how unpredictable or disordered the text is. Higher entropy indicates greater diversity in character usage; lower entropy suggests repetitive patterns. This metric is fundamental to information theory, cryptography, and data compression, helping professionals understand the strength and efficiency of their data.

To use this tool, simply paste your text into the input field and click 'Calculate'. The calculator instantly returns the Shannon entropy value (in bits per character) and shows the individual character frequency data. It works on any text—passwords, document samples, code snippets, or natural language—and handles special characters, whitespace, and Unicode. This makes it an essential aid for security analysts evaluating password quality, engineers assessing compression potential, and researchers studying text patterns.

Keep in mind that high entropy alone does not guarantee good passwords; entropy reflects distribution diversity, not true randomness. The tool assumes each character is equally likely (maximum entropy) based on what it observes, so true cryptographic security also depends on the generation method. For large texts, entropy stabilizes around the natural language baseline (~1.5 bits per character for English), while shorter samples may show higher variability.

Frequently Asked Questions

Code Implementation

import math
import re

def password_entropy(password: str) -> float:
    """Calculate Shannon entropy in bits for a password."""
    pool = 0
    if re.search(r"[a-z]", password): pool += 26
    if re.search(r"[A-Z]", password): pool += 26
    if re.search(r"[0-9]", password): pool += 10
    if re.search(r"[^a-zA-Z0-9]", password): pool += 32  # common special chars
    if pool == 0:
        return 0.0
    return len(password) * math.log2(pool)

def shannon_entropy(text: str) -> float:
    """True Shannon entropy based on character frequency."""
    from collections import Counter
    counts = Counter(text)
    n = len(text)
    return -sum((c / n) * math.log2(c / n) for c in counts.values())

# Examples
print(f"'password' entropy: {password_entropy('password'):.1f} bits")    # ~37.6
print(f"'P@ssw0rd!' entropy: {password_entropy('P@ssw0rd!'):.1f} bits")   # ~52.5
print(f"Random 16-char (all types): {password_entropy('aB3!xK9#mN2@pQ7^'):.1f} bits") # ~104.8

# Strength rating
def strength(bits: float) -> str:
    if bits < 28: return "Very Weak"
    if bits < 36: return "Weak"
    if bits < 60: return "Reasonable"
    if bits < 80: return "Strong"
    return "Very Strong"

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.