📘 CodingMarble Learn

Information Theory

Information is something that removes uncertainty. We measure it in bits: one bit is the answer to one fair yes/no question. If N outcomes are equally likely, the information is I = log2 N bits (Hartley). If outcomes have different probabilities, the average information is H = −Σ p log2 p bits (Shannon). Information is created, stored, processed and transferred through a channel that may add noise.

🎬 Step-by-step story

  1. A ball hides in one of 8 boxes. That is 8 possible places. Tap Give a clue. Each yes/no clue cuts the doubt in half. Three clues find the ball: 3 bits.
  2. Information can be a smooth wave or a set of steps. Computers use steps (discrete). Pick the number of levels and see how the steps copy the wave.
  3. Information is created at a source, stored, processed and sent through a channel to a receiver. Noise (red packets) can damage it on the way. Move the noise slider.
  4. Hartley: with N equally likely choices you need log2 N yes/no questions. Pick N and watch the yellow bit lamps. 8 choices need 3 bits, 16 need 4.
  5. Shannon: some symbols are common and some are rare. Rare ones carry more information. The average H is 1.75 bits for these four symbols and 2 bits when they are equal.
  6. Free play: change the chance of heads of a coin. A fair coin gives the most information, 1 bit. A coin that nearly always lands the same way gives almost none.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why is a bit a yes/no answer?

A yes/no question has two answers, so it can halve the choices. Each clue in the 3D halves the boxes.

Why do computers use steps instead of smooth waves?

Steps can be written as whole numbers (bits), copied exactly and fixed after noise. Change the levels to see the steps follow the wave more closely.

Does noise destroy information?

It can flip bits, shown as red packets. Systems add check bits or repeat data to spot and fix errors.

Why log base 2?

Because each question has two answers. Every extra bit doubles the number of choices, so choices N = 2^bits, and bits = log₂ N.

Why do rare symbols carry more information?

A rare symbol surprises you more and rules out more possibilities. In the bars, p = 1/8 gives 3 bits but p = 1/2 gives only 1.

Why is a fair coin the hardest to predict?

Neither side is favoured. Move the slider: the curve is highest at p = 0.5 and falls to 0 at the ends.

What is information? Data, discreteness and the bit

Data are signs we can write down: letters, numbers, pixels, sounds. They become information when they tell us something new and reduce our doubt.

A bit is the smallest piece of information: the answer to one fair yes/no question, written 0 or 1. A byte is 8 bits.

Discrete and continuous

A continuous signal, like a sound wave, can take any value. A discrete signal takes only separate values, like steps. To store a wave on a computer we measure it at times (sampling) and round each value to one of a few levels (quantising). With 2 levels each sample needs 1 bit; with 16 levels, 4 bits.

Information processes: storage, processing, transfer

Information goes through four kinds of steps.

Real channels have noise that can flip bits. Systems add check bits or repeat the message so the receiver can spot and fix errors. A channel also has a limit on speed, called its bandwidth or bit rate (bits per second).

Measuring information: Hartley's formula

Suppose there are N equally likely outcomes. Each yes/no question can halve the choices. So the number of questions needed is the power of 2 that gives N:

I = log₂ N bits (Hartley's formula)

8 choices: log₂ 8 = 3 bits. 64 choices: 6 bits. If N is not a power of 2 the answer is a fraction, like log₂ 6 ≈ 2.58 bits for a die, and you round up to whole yes/no questions.

For a message of k symbols from an alphabet of N symbols: total information = k × log₂ N bits.

Shannon's entropy: unequal probabilities

If outcomes are not equally likely, a rare outcome surprises us more. The information of one outcome with probability p is −log₂ p bits (p = 1/2 gives 1 bit, p = 1/8 gives 3 bits). The average information per symbol, called entropy, is:

H = −Σ p·log₂ p (Shannon's formula)

For probabilities 1/2, 1/4, 1/8, 1/8: H = 0.5·1 + 0.25·2 + 0.125·3 + 0.125·3 = 1.75 bits. For four equal outcomes H = 2 bits, which equals Hartley's value. Equal probabilities give the largest H. A sure outcome (p = 1) gives H = 0.

Why it matters: if H is small, the message can be compressed to about H bits per symbol.

Try it: twenty questions

Ask a friend to think of a number from 1 to 64. Find it with yes/no questions only. Can you do it in 6? (Hint: always ask 'Is it in the top half?'.) Now try with the numbers 1 to 100. How many questions do you need at most?

Key formulas and definitions

Worked examples

1. A ball is in one of 64 boxes. How many bits of information find it?

I = log₂ 64 = 6 bits (6 yes/no questions).

2. A message has 20 letters from a 32-letter alphabet. How many bits is it?

Each letter gives log₂ 32 = 5 bits. Total = 20 × 5 = 100 bits.

3. How many bits are in an 8-level grey pixel, and in a 10 × 10 image of such pixels?

One pixel: log₂ 8 = 3 bits. Image: 100 × 3 = 300 bits.

4. Find the entropy of a source with probabilities 1/2, 1/4, 1/8, 1/8.

H = ½·1 + ¼·2 + ⅛·3 + ⅛·3 = 0.5 + 0.5 + 0.375 + 0.375 = 1.75 bits.

5. Find the information in an event of probability 1/16.

i = −log₂(1/16) = log₂ 16 = 4 bits.

6. How long does it take to send a 10 MB file over a 2 Mbit/s channel? (1 MB = 8 Mbit)

10 MB = 80 Mbit. Time = 80 ÷ 2 = 40 s.

7. How much information does a fair die roll give?

log₂ 6 ≈ 2.58 bits.

Common mistakes

Practice quiz

1. A bit is:
2. How many bits are needed to choose among 16 equally likely items?
3. Which signal is discrete?
4. Noise in a channel can:
5. The entropy of a fair coin toss is:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is information theory in simple words?

The study of how to measure, store, process and send information. It tells us how many bits a message needs and how much a channel can carry.

What is the Hartley formula?

I = log₂ N: the number of bits needed to pick one of N equally likely options.

What is Shannon entropy?

The average information per symbol of a source with unequal probabilities: H = −Σ p log₂ p.

Where this is taught

Russia7 классTheoretical foundations
Russia10 классTheoretical foundations
Russia11 классTheoretical foundations

Learn first

Learn next

Related lessons

All Computer Science lessons