Shannon and the Bit of Information
In 1948 Claude Shannon founded information theory with “A Mathematical Theory of Communication”. This demo plots the binary entropy H(p), marks the current probability, and connects log2(N) to the number of yes/no questions needed to identify one of N equally likely outcomes.
H(p) = −p·log2(p) − (1−p)·log2(1−p) = 1.0000 bits · outcomes H = log2(8) = 3 bits
8 equally likely outcomes need 3 bits, i.e. 3 yes/no questions at most. Entropy is the minimum average number of questions.
Each yes/no question has at most 2 answers, so 20 questions distinguish at most 2^20 ≈ 1,048,576 items. One million equally likely items carry log2(1,000,000) ≈ 19.93 bits, so 20 questions are enough.
A fair coin (p = 0.5) carries one full bit of uncertainty. Push p toward 0 or 1 and the outcome becomes predictable, so H(p) drops toward zero. The outcome buttons show the same idea for many equally likely results: N outcomes carry log2(N) bits, the number of yes/no questions needed to identify one.
What you are seeing
The binary entropy H(p) = −p·log2(p) − (1−p)·log2(1−p) measures the average uncertainty of a coin with heads probability p.
With N equally likely outcomes, the entropy is log2(N) bits. That equals the minimum number of yes/no questions needed on average to find the answer.
The bit is the unit: one fair coin flip has entropy exactly 1. Predictable outcomes have entropy near 0.
Why it matters
Shannon’s framework underlies compression, error correction, cryptography, and machine learning. It explains both the limits of data compression and why 20 yes/no questions can pinpoint one item out of a million.
Complexity & details
Evaluating H(p) is O(1). Checking N outcomes costs O(1) for log2(N); building a full decision tree would cost O(N).
Frequently asked questions
Why is entropy zero when p is 0 or 1?+
If the outcome is certain, observing it tells you nothing new. There is no uncertainty to reduce, so the information gained is zero bits.
Why 20 questions for a million items?+
Each yes/no question can at most double the number of distinguishable cases. After k questions you can separate at most 2^k items, and 2^20 is slightly more than one million.