Skip to main content
ExplainerInformation TheoryExplainer· 7 min read· in Science

The H = -∑ p_i log_2 p_i Formula: How the Average Number of Bits Measures the Uncertainty of a Random Variable

Claude Shannon's 1948 entropy formula proves that information is not determined by message length, but by the mathematical probability of surprise. The equation sets an absolute physical limit on data compression by calculating the exact number of binary decisions needed to resolve uncertainty.

By Nicolas Laurent

Information Theorists 40%Machine Learning Engineers 40%Cognitive Scientists 20%
Information Theorists
Focus on the mathematical limits of data compression and transmission.
Machine Learning Engineers
Utilize entropy as an optimization metric to train predictive models.
Cognitive Scientists
Question the formula's applicability to biological intelligence and semantic meaning.

Perspectives this story doesn't cover

  • Quantum Information Physicists
1.0 bit
Entropy of a fair coin flip
2.62 bits
Calculated entropy per letter of the English language
4.70 bits
Theoretical maximum entropy of a random 26-letter alphabet

It is a common intuition that the amount of information in a message is determined simply by its length—that a 1,000-word document inherently contains more information than a 10-word sentence. The foundational mathematics of communication contradict this directly. According to Claude Shannon's 1948 theorem, information is not a measure of volume, but a measure of surprise. If a long message is entirely predictable, it contains zero information. The actual data dictates that the true information content of any random variable is quantified by its entropy, a metric that calculates the average number of bits required to resolve the uncertainty of its outcome.[1][2]

The formula that defines this limit is $H = -\sum p_i \log_2 p_i$, where $H$ represents Shannon entropy, $p_i$ is the probability of each possible outcome, and the base-2 logarithm grounds the result in binary digits, or bits. This equation sets an absolute, mathematical floor on how tightly data can be compressed without losing fidelity. By multiplying the probability of a state by the logarithm of that probability, and summing across all possible states, the formula outputs the exact average number of yes-or-no questions needed to determine the variable's true state.[3][4]

To understand the mechanism, consider the simplest random variable: a fair coin flip. The probability of heads is 0.5, and the probability of tails is 0.5. Plugging these into the formula yields an entropy of exactly 1.0 bit. The data shows that it takes exactly one binary decision to resolve the uncertainty of a fair coin. Because both outcomes are equally likely, the system is at maximum uncertainty for a two-state variable, meaning the receiver learns exactly one full bit of information when the outcome is revealed.[4][5]

A perfectly fair coin flip represents maximum uncertainty for a two-state system, yielding exactly one bit of entropy.

However, the evidence shifts when the probabilities become skewed. If a weighted coin lands on heads 99 percent of the time, the uncertainty drops precipitously. The formula calculates the entropy of this biased coin at just 0.08 bits. Because the outcome is almost entirely predictable, the average amount of surprise—and therefore the average information generated by each flip—approaches zero. A receiver watching this biased coin flip learns very little new information from each toss, allowing the data to be heavily compressed.[1][2]

This mechanism scales directly to complex systems, such as human language and text transmission. If the 26 letters of the English alphabet appeared completely at random, with each character having an equal 1-in-26 chance of occurring, each letter would carry an entropy of 4.70 bits. But empirical analysis of English text reveals strict statistical patterns: the letter 'q' is almost always followed by 'u', and vowels appear with highly predictable frequencies. These structural rules mean that a reader already possesses partial information about the next letter before it is even revealed, lowering the overall uncertainty of the sequence.[4]

By accounting for these probabilities, Shannon calculated that the actual entropy of the English language is only 2.62 bits per letter. This figure demonstrates that patterns reduce uncertainty, allowing a highly structured system to communicate complex messages using relatively little underlying information. Because the true entropy is nearly half of the theoretical maximum, English text contains significant redundancy. This redundancy is precisely what allows modern file compression algorithms, such as ZIP or gzip, to shrink text files to a fraction of their original size without losing a single character.[3][4]

Because English text contains predictable patterns, its actual entropy is significantly lower than a random sequence of letters.
By accounting for these probabilities, Shannon calculated that the actual entropy of the English language is only 2.62 bits per letter.

The implications of this formula form the bedrock of modern digital infrastructure. As information theorist Tara Javidi notes, 'Shannon showed there is something like the speed of light, a fundamental limit.' The entropy rate of a data source dictates the absolute minimum channel capacity required to transmit it reliably, ensuring that 'Shannon entropy is a fundamental limit for how much we can compress a source, without risking distortion or loss.' No lossless compression algorithm can encode a sequence in fewer bits than its Shannon entropy.[1][2][4]

In machine learning, the formula is adapted to evaluate the quality of predictive models. Decision trees utilize a concept called information gain, which measures the reduction in entropy achieved by splitting a dataset along a specific feature. The algorithm calculates the entropy of the dataset before the split, and subtracts the weighted entropy of the resulting subsets. By selecting the split that maximizes this information gain, the model minimizes the remaining uncertainty, effectively isolating the most predictable subsets of data to improve classification accuracy.[5]

Similarly, neural networks rely heavily on cross-entropy loss to quantify the divergence between their predicted probabilities and the actual distribution of the training data. By penalizing confident but incorrect predictions exponentially more than uncertain ones, the network minimizes its internal entropy. As the model trains over thousands of epochs, it continuously tunes its internal weights to better reflect the true probability distribution of the dataset, driving the cross-entropy loss downward toward the theoretical minimum established by Shannon's original 1948 equation.[3][5]

Machine learning models use entropy to measure uncertainty, splitting data to maximize information gain.

Despite its universal application, the evidence supporting the formula's utility in certain domains remains thin. Shannon explicitly designed the metric to address the engineering problem of signal transmission, deliberately stripping away the semantic meaning of the message. The formula treats a sequence of random characters and a line of Shakespeare identically, provided their probability distributions match. This strict focus on syntactic probability means that Shannon entropy cannot distinguish between profound wisdom and complete gibberish, so long as both sequences are equally unpredictable.[1][2]

This semantic blindness limits the formula's ability to measure the true usefulness of information in biological or cognitive systems. While neuroscientists attempt to apply Shannon entropy to map the information processing capacity of the human brain, the data is noisy and the correlations are weak. The brain does not process information as a sequence of independent, identically distributed symbols. Instead, cognitive systems rely on context, memory, and physical embodiment, variables that resist clean categorization into discrete probability distributions.[3][6]

Furthermore, calculating the exact entropy of highly complex, continuous variables requires integrating over infinite probability density functions, a process known as differential entropy. In practice, this requires significant mathematical approximations, introducing uncertainty into the exact limits of compression for continuous analog signals like high-fidelity audio or video. Because a truly continuous signal can take on an infinite number of states, its absolute entropy is technically infinite, forcing engineers to rely on quantization and acceptable loss thresholds rather than the pure lossless limits defined by the discrete formula.[1][2]

Every piece of data transmitted across modern networks is constrained by the mathematical floor of Shannon entropy.

The formula also assumes that the probability distribution of the source is stationary and fully known to both the sender and the receiver. In real-world communication networks, probabilities fluctuate dynamically, requiring adaptive compression algorithms that estimate entropy on the fly. The theoretical floor set by Shannon is rarely achieved in practice due to this operational overhead. Compressing data requires sending the compression dictionary alongside the message, adding a structural penalty that keeps real-world transmission rates slightly above the absolute mathematical limit.[4][5]

The $H = -\sum p_i \log_2 p_i$ formula remains a defining triumph of 20th-century mathematics. By proving that information is a quantifiable, physical property tied to probability, the equation transformed communication from a qualitative art into a rigorous science. The next frontier lies in reconciling this syntactic measure of uncertainty with the semantic meaning it carries, a challenge that continues to drive research in artificial intelligence and cognitive science. Until then, every bit of data transmitted across the globe remains bound by the limits Shannon calculated.[1][6]

What we don’t know

  • How to mathematically quantify the semantic 'meaning' or usefulness of information, rather than just its syntactic probability.
  • The exact information processing capacity and entropy limits of the human brain's neural networks.
  • Whether the fundamental limits of Shannon entropy can be bypassed using quantum entanglement and quantum information theory.

Key points

  • Shannon entropy proves that information is a measure of surprise, not the physical length of a message.
  • The formula calculates the absolute minimum number of bits required to compress and transmit data losslessly.
  • A fair coin flip contains exactly 1.0 bit of entropy, while highly predictable events contain near-zero entropy.
  • Machine learning relies on entropy to train models, using it to measure and minimize the network's uncertainty.

How we got here

  1. 1948

    Claude Shannon publishes 'A Mathematical Theory of Communication', introducing the entropy formula.

  2. 1952

    David Huffman develops Huffman coding, a practical algorithm that approaches the Shannon entropy limit for data compression.

  3. 1990s

    Cross-entropy loss becomes a standard optimization metric for training early artificial neural networks.

  4. 2020s

    Large language models utilize entropy minimization at an unprecedented scale to predict and generate human-like text.

Sources

Source coverage

6 outlets

3 viewpoints surfaced

Information Theorists 40%Machine Learning Engineers 40%Cognitive Scientists 20%
  1. [1]Bell System Technical JournalInformation Theorists

    A Mathematical Theory of Communication

    Read on Bell System Technical Journal
  2. [2]arXivMachine Learning Engineers

    Understanding Shannon's Entropy metric for Information

    Read on arXiv
  3. [3]ZenodoCognitive Scientists

    A summary of Claude Shannon Information Theory

    Read on Zenodo
  4. [4]Quanta MagazineInformation Theorists

    How Shannon Entropy Imposes Fundamental Limits on Communication

    Read on Quanta Magazine
  5. [5]Machine Learning MasteryMachine Learning Engineers

    A Gentle Introduction to Information Entropy

    Read on Machine Learning Mastery
  6. [6]Factlen Editorial TeamCognitive Scientists

    Synthesis by Factlen editorial team

    Read on Factlen Editorial Team

Comments

Stay informed

Every angle. Every day.

Get Science stories with full source coverage and perspective breakdowns delivered to your inbox.