Home / Information

Entropy and Information

Drag the bars and watch uncertainty rise and fall. Entropy is how many yes/no questions you would need to pin the answer down.

Distribution

2
0.00

0 = uniform, 1 = all on one outcome


The Distribution

sum = 1.000

Drag any bar to change its probability. The rest rescale to keep the total at 1.

Entropy of a Two-Outcome Event

Maximum at p = 0.5, zero at both ends. The marker is the current split when there are two outcomes.

Uncertainty

Entropy
1.000
bits
Maximum Possible 1.000
Fraction of Max 100%
Gini Impurity 0.500

Surprise per Outcome

Each outcome's surprise is −log₂(p). Entropy is the average surprise, weighted by how often each outcome happens.

Entropy and Information

Information measures surprise; entropy is the average surprise under a probability distribution.

Entropy depends on the distribution and units

Entropy is highest for a uniform distribution over a fixed finite set: if there are n equally likely outcomes, H = log₂(n). Changing the logarithm base changes units, not the underlying uncertainty: base 2 gives bits and base e gives nats.

Entropy does not measure the importance of an outcome or uncertainty about every aspect of a system. It is defined relative to a probability model. In machine learning, it appears in cross-entropy and KL divergence and in information gain.

Calculate uncertainty for a biased coin

Suppose a coin lands heads with probability 0.9 and tails with probability 0.1. The entropy is −0.9log₂(0.9)−0.1log₂(0.1)≈0.469 bits, less than the 1 bit for a fair coin. The rare tail carries more self-information (−log₂0.1≈3.32 bits) than the common head (−log₂0.9≈0.15 bits), but the tail occurs less often; entropy averages both contributions using their probabilities. If the outcome is certain, its surprise is zero and entropy is zero.

Entropy measures uncertainty about the outcome under a specified distribution, not the importance of the outcome or the amount of data stored by every encoding system. For n equally likely outcomes it is log₂n bits, and no distribution on those same n outcomes has higher entropy. Entropy also depends on how outcomes are defined: grouping several outcomes together changes the distribution and its entropy. Use the same outcome categories and logarithm base when comparing values. In machine learning, entropy can quantify label uncertainty before and after a split; information gain makes that reduction explicit.

Try this above

Make the outcome probabilities more or less balanced. Entropy should increase as the distribution approaches uniformity and decrease as one outcome becomes nearly certain.

Entropy is additive for independent discrete variables: if X and Y are independent, H(X,Y)=H(X)+H(Y). If they are dependent, knowing X can reduce uncertainty about Y, and H(X,Y)=H(X)+H(Y|X). Conditional entropy measures the remaining average uncertainty after X is known. This makes entropy useful for reasoning about compression and prediction, but the result depends on the probability model and the granularity of the categories. A model that assigns incorrect probabilities gives an entropy value for that model, not an objective measure of every kind of uncertainty.

For a fair six-sided die, entropy is log₂6≈2.585 bits. This is an average uncertainty, so it need not be a whole number even though any one outcome can be represented with a finite code. An efficient code assigns shorter descriptions to common outcomes and longer ones to rare outcomes; entropy is the ideal lower bound on average code length under suitable coding assumptions. It does not prescribe a unique code or count the physical bits in every data format.

Sources and next steps

Overview

Surprise and its average

An event with probability p has self-information −log₂(p) bits. Rare events carry more information than common ones. For a discrete random variable X with probabilities pᵢ, Shannon entropy is the expected self-information:

H(X) = −Σᵢ pᵢ log₂(pᵢ)

For a fair coin, H = 1 bit. For a coin that always lands heads, H = 0 because the outcome is certain. The convention 0 log 0 = 0 is understood by continuity.

Predict, then reveal

About to run: set Number of Outcomes to its maximum (8). Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Check yourself

0 of 2

Answer without scrolling back up.

  1. Which event carries more self-information?

  2. What is the entropy of a certain outcome?

Cheat sheet

Entropy and Information

Drag a distribution and watch uncertainty rise and fall. Entropy is the average surprise, and the quantity every classification loss is built from.

MATHS · vizlearn.in/maths/entropy_and_information.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.