Hands-on Computer Science
My learning DE

Lesson25 min

Symbols and information

How distinguishable states become symbols through an agreement, how halving yes-or-no questions count information in bits, and what a bigger alphabet gains in bits per symbol and costs in safety.

Topics:Representing informationTransferring information

See first: Analog and digital

What you will learn

Using a light link with several colours, this lesson shows you how light becomes a symbol and how much information it carries, and afterwards you can:

  • explain why a symbol is an agreed and distinguishable state, and why an error-free transmission without a shared table still delivers nonsense
  • argue why halving yes-or-no questions always find one of 32 cards in five questions and on average deliver more information than a lopsided question
  • calculate the uncertainty with H = log₂(N) and the information of an answer with I = H₁ − H₂, both in bits, and check them with math.log2()
  • work out how many bits a symbol from N equally likely colours carries, how this changes the transmission time of a file, and why two symbols in groups are still enough for any message
  • explain why Morse code gives the frequent letter e the shortest code
  • weigh why more colours bring more bits per symbol but move closer together, so that only a measurement series can settle the size of your own alphabet
In a new window As PDF

North Atlantic, 1942: radio traffic would give the convoy away, so the ships keep radio silence and talk to each other anyway, with a lamp and a shutter in front of it, short, short, short, long. The light itself knows nothing about letters, and it means something only because both ships carry the same table. This lesson is about the two halves of that situation: what turns a state into a symbol, and how much a symbol can tell you. The running example is a link that transmits data with light, where an LED sends colours and a sensor tells them apart.

Distinguishable and agreed

A symbol is an agreed, distinguishable state, and both words carry weight. Distinguishable is a question of physics and of the receiver: can it tell this state apart from all the others, even with noise on the way? That question was the subject of Analog and digital. Agreed is a question of a different kind, which no measurement can answer, since it asks what the state stands for, and only the people on both ends can settle that.

A raised thumb shows both halves. Nobody mistakes it for a fist or an open hand, so it is easy to distinguish, but the thumb itself holds no meaning: in much of Europe it says "good", in parts of West Africa and the Middle East it is an insult, and someone from Germany who counts on their fingers raises the thumb for "one", where someone from the United States raises the index finger.

The set of all symbols that sender and receiver have agreed on is their alphabet. The 26 letters from A to Z are one alphabet, but four colours of a lamp, two tones or a flag that is either raised or lowered are alphabets just as well.

Perfect reception, perfect nonsense

What happens when the agreement is missing is easy to show. The sender spells team with four colours, red for t, green for e, blue for a and yellow for m, and all four colours arrive without a single error. The receiver's table, however, swaps red and yellow:

Both tables map colours to letters, but not the same way: four colours arrive without a single error, and the receiver reads a different word.

The program decodes the same four colours with both tables:

received = ["red", "green", "blue", "yellow"]   # every colour arrived correctly

sender_table = {"red": "t", "green": "e", "blue": "a", "yellow": "m"}
receiver_table = {"red": "m", "green": "e", "blue": "a", "yellow": "t"}

meant = ""
read = ""
for colour in received:
    meant += sender_table[colour]
    read += receiver_table[colour]

print("Meant:", meant)
print("Read: ", read)

There was no transmission error, no interference and no bad measurement, and the message is still wrong. Worse, team turned into meat, another real word, so nobody notices that anything went wrong. Change one entry in receiver_table and run the program again: as long as the two tables differ, the signal can be perfect and the meaning still wrong.

In code, the agreement is a dictionary like sender_table. It is never transmitted; it has to sit on both sides beforehand, which makes it not data but a promise, and whoever changes it without telling the partner builds the nonsense above. The same dictionary can just as well map colours to bit strings, {"red": "00", "green": "01", "blue": "10", "yellow": "11"}, and how many digits such a string needs is the subject of the next part.

The guessing game, measured

What a message is worth does not depend on its length but on how much uncertainty it removes. Someone draws one card from a deck of 32, and you may only ask questions that can be answered with yes or no. Ask well, for example "is it red?", then "is it a heart?", and you are done after five questions:

Every question halves what is left, so five questions are enough, and not by luck.

That number of necessary halvings is the measure this part is about, and its unit is the Bit: a question that halves the field is worth one bit. You can watch the halving at work: think of a number from 1 to 32 and let the program find it, answering each question with y or n:

low, high = 1, 32
questions = 0

while low < high:
    middle = (low + high) // 2
    answer = input(f"Is your number greater than {middle}? (y/n) ")
    questions += 1
    if answer == "y":
        low = middle + 1
    else:
        high = middle

print(f"Your number is {low}, found with {questions} questions.")

Whatever number you choose, the program needs exactly five questions, because every answer removes half of what is left.

Not every answer is worth the same

A lopsided question buys less. "Is it the ace of spades?" can settle everything at once, but it does so in only one of 32 cases, and in the other 31 almost everything is still left. The halving question, on the other hand, always delivers exactly one bit, whatever the answer. A rare answer tells you a lot, an expected answer tells you little, and since you cannot choose which one you get, what counts is the average:

Question Chance of yes Yes is worth No is worth On average
"is it red?" 1/2 1 bit 1 bit 1 bit
"is it the ace of spades?" 1/32 5 bits 0.05 bits 0.2 bits

In general, every possible answer contributes how likely it is, multiplied by what it would be worth, and added up over all answers that is the expected value of a question:

E = Σ pᵢ · log₂(1 / pᵢ)

Here pᵢ is the probability of an answer and log₂(1 / pᵢ) is what that answer is worth in bits: the less likely it is, the more it carries. For a yes-or-no question that is two terms, and the function worth() puts the numbers in:

import math

def worth(p_yes):
    p_no = 1 - p_yes
    return p_yes * math.log2(1 / p_yes) + p_no * math.log2(1 / p_no)

print(round(worth(1 / 2), 2))
print(round(worth(1 / 32), 2))

Worked out by hand, the halving question gives ½ · 1 + ½ · 1 = 1 bit and the question about the ace of spades 1/32 · 5 + 31/32 · 0.05 ≈ 0.16 + 0.05 ≈ 0.2 bits. A whole bit goes only to the question that really splits the field in half, which is why halving wins on average: it takes the largest guaranteed gain out of every answer, and the lopsided question pays off only at the very end, when just two possibilities are left. The second row also shows that a question whose outcome is nearly certain carries almost no information, however long its answer, and compression rests on exactly that observation. In the question game here you measure this yourself on sixteen faces: after every question it shows how many bits the answer gained and what the question was worth on average.

Demo Question game

How to use: Tap a question to ask it, or a face to guess; a guess counts as a question too. The game does not show how many faces would answer yes, since counting them is your strategy. After every answer, the panel below the questions shows how many bits it gained and what the question was worth on average, so you can tell a well planned question from a lucky one.

One bit, and two formulas

Put generally, a bit is the amount of information in a decision between two equally likely possibilities. A light switch holds one bit, and it needs no computer for that. With it, both quantities can be written down. The uncertainty of N equally likely possibilities is

H = log₂(N) bits

and measures how many halvings are still missing. Information is a difference, the uncertainty before minus the uncertainty after,

I = H₁ − H₂

and measures what an answer has actually removed. 32 cards mean an uncertainty of 5 bits, and each halving question removes 1 bit; the 32 is the space of possibilities, while the uncertainty is the 5. Python calculates the logarithm with math.log2():

import math

for n in [2, 4, 32, 26]:
    print(n, "possibilities:", round(math.log2(n), 2), "bits")

Two possibilities give one bit, four give two and 32 give five. For 26 letters the result is 4.7 bits, which is not a whole number of questions: a code made of yes/no symbols needs five of them per letter, since four give only 2⁴ = 16 combinations and five give 32, the same kⁿ as in Place value systems.

What a bigger alphabet buys

The same tool tells you what a symbol is worth. Each symbol from an alphabet of N equally likely colours carries log₂(N) bits, so two colours carry one bit per symbol, four carry two, eight carry three and sixteen carry four. Because the same file then needs fewer symbols, it gets through sooner:

The same file at the same symbol rate: only the alphabet changes, and with it the time the file needs.

With four colours the file needs half the time it needs with two, with eight a third and with sixteen a quarter, while the file and the symbol rate stay the same.

At the other end, two symbols are enough for any message at all; they only need more room. Five flashes with two possibilities each give 2⁵ = 32 combinations, enough for a whole alphabet. What a large alphabet achieves per symbol, two symbols achieve in a group, and that is why every computer gets by with 0 and 1 (Place value systems): a small alphabet is not a dead end but merely slower.

When symbols are not equally likely

Everything so far assumed that all symbols are equally likely. In real text they are not, and Morse code makes use of that: the most frequent letter in English, e, gets the shortest code, a single dot, t gets a single dash, and a rare letter such as q takes four signals, − − · −.

The unequal treatment pays off because it shortens the average message: what occurs often should cost little, and compression methods still shrink files on the same principle today. A rare symbol carries more information than a common one, so it may also take up more room. Codes of unequal length have a price of their own, though, since the receiver has to find out where one code word ends; Morse code uses pauses for that, and a prefix-free code gets by without them.

Your alphabet

So why not use 256 colours? More colours bring more bits per symbol, so the same file needs fewer symbols and arrives sooner, but the colours also move closer together, the noise reaches across the gap, and symbols are read wrong, as Analog and digital and Signal and noise show. No formula tells you where the limit lies, so the size of your alphabet is not a matter of taste but the result of a measurement. Challenge 1: The alphabet asks exactly this, and four steps lead to the answer:

  1. agree on your alphabet and write it down
  2. measure a profile for every symbol
  3. teach the receiver to recognise every symbol
  4. send 20 random symbols and count the errors

The first step is the one everyone wants to skip, and whoever keeps the agreement only in their head builds the nonsense from the first part as soon as two people work in parallel. Light means nothing until you agree what it means, and how much it means, you can count.

Takeaways

  • A symbol is an agreed, distinguishable state: physics decides whether it can be told apart, and only an agreement decides what it means.
  • The agreement, such as a dictionary of colours and letters, has to exist on both sides beforehand; if it differs, perfect reception gives perfect nonsense.
  • A question that halves the field is worth one bit; a lopsided question is worth much less on average, even if it might settle everything.
  • With N equally likely possibilities the uncertainty is H = log₂(N) bits, and the information of an answer is I = H₁ − H₂.
  • A symbol from N equally likely symbols carries log₂(N) bits, so larger alphabets are faster, and two symbols in groups are enough for any message.
  • Frequent symbols deserve short codes, which is why Morse code gives the e a single dot.
  • More colours move closer together, so only a measurement series settles the size of your own alphabet.

Quiz: symbols and information

What is a symbol in the sense of information theory?

  • A small picture, such as an icon on a screen.
  • A written character such as a letter or a digit, that is, something you can write down.
  • An agreed, distinguishable state.
  • A single sensor reading, such as a particular brightness.

Two teams send data with coloured light, and their LED shows four colours they have agreed on. What is the alphabet of their link?

  • The 26 letters from A to Z that the link is meant to carry.
  • The set of the four colours that both teams have agreed on as symbols.
  • The order in which the colours of a message are sent.
  • The mapping of the colours to bit sequences, such as green standing for 01.

A link sends letters as coloured flashes of light. Who decides that a green flash means "A"?

  • The physics of light: each colour has a fixed wavelength, and from that the receiver recognises which character is meant.
  • Sender and receiver together, by an agreement made before the transmission.
  • A standard for light transmission that all devices follow so that they understand each other.
  • The receiver alone, since it is the side that has to turn readings into characters.

What is a bit?

  • A tiny component inside a computer that either passes or blocks current.
  • The amount of storage a computer needs for a single character such as "A".
  • The amount of information in a decision between two equally likely possibilities.
  • The smallest brightness a sensor can still measure.

An alphabet has four colours, all equally likely. How much information does a single received symbol carry, and why?

  • 4 bits, because each of the four colours is a possibility of its own, and each possibility counts as one bit.
  • 2 bits, because two yes/no decisions suffice to determine one of four colours.
  • 1 bit, because the receiver makes one decision per symbol: it has arrived or it has not.
  • It depends on the colour sent, because an easily recognised colour such as red carries more than a hard one such as yellow.

A link switches from 2 to 8 colours and still sends the same number of symbols per second. How does the transfer time of the same file change?

  • It drops to a quarter, because 8 divided by 2 is 4.
  • It drops to a third: each symbol now carries 3 bits instead of 1.
  • It stays the same, since the symbol rate has not changed.
  • It drops to an eighth, one eighth per colour.

More symbols per alphabet means more bits per symbol. Why not simply make the alphabet huge, say 256 colours?

  • Because a lamp can mix only a limited number of distinct colours from its three channels.
  • Because the receiver would need a lookup table for 256 colours whose search per symbol takes too long.
  • Because the receiver must still tell the symbols apart reliably: the more there are, the closer their measurement regions crowd together.
  • Because an alphabet needs only as many symbols as the text has distinct characters; further colours would go unused.

A receiver recognises every colour without error; recognition accuracy is 100 percent. Yet the resulting text is nonsense. What is the most likely cause?

  • The sensor delivers distorted readings, for instance because the gain is set too high.
  • Sender and receiver use different mappings from colours to characters.
  • Ambient light shifts the readings, so the receiver sees the colours but sorts them into the wrong regions.
  • The alphabet has fewer colours than the text has distinct characters, so several characters end up on the same colour.

An alphabet has 16 symbols. At most how many yes/no questions are needed to determine a received symbol with certainty?

  • 4, because halving four times leads from 16 possibilities to one.
  • 8, because each question halves, and half of 16 possibilities is 8.
  • 15, because in the worst case you have to rule out 15 symbols one by one.
  • 2, because every question has two answers, and two times two answers cover 16.

Which statements about bits are true?

  • One bit distinguishes exactly two possibilities.
  • A bit and a byte denote the same amount, just in different contexts.
  • Any information can be represented as a sequence of bits.
  • Bits exist only in computers, because only there are states stored electrically.
  • A message contains more bits if its content is more important.

An alphabet has four colours, so each symbol carries 2 bits. A 12-bit identifier is to be transmitted. How many symbols does that take at least?

  • 12, one symbol per bit.
  • 6, because 12 bits divided by 2 bits per symbol.
  • 3, because 12 divided by 4 colours.
  • 24, each bit twice to be safe.

Why is an alphabet of just two symbols in principle enough for any message, however complicated?

  • It is not enough: text needs at least 26 symbols.
  • Because two symbols lie furthest apart in the signal, so the receiver never confuses them.
  • Because every symbol of a larger alphabet can be replaced by a fixed group of two-way symbols; it only costs length.
  • Because computers work with two states internally anyway, so every message is already in that form before sending.

In terms of symbols and information, what does this dictionary establish?

ALPHABET = {
    "red":    "00",
    "green":  "01",
    "blue":   "10",
    "yellow": "11",
}
  • The four colours a lamp can produce, each with the code the manufacturer assigned to it.
  • The agreement: which symbol carries which group of bits. The receiver needs exactly the same mapping, only in reverse.
  • The order in which the colours are sent: first red, then green, then blue, then yellow.
  • How many symbols are sent per second, because two bits per symbol determine the pace of the transmission.

Sixteen faces, one of them is the secret. Question A is "does it wear glasses?", and eight of the sixteen do. Question B is "is it face number 7?". Which question is worth more on average?

  • Question A: it yields a guaranteed 1 bit, question B only about a third of that on average.
  • Question B: a yes solves the puzzle completely at once, which A can never do.
  • Both the same: they are both yes/no questions, and a yes/no answer is one bit.
  • That depends on luck and cannot be said in advance.

In Morse code the most common letter, "e", is also the shortest: a single dot. Rare letters like "q" are long. Why does that unequal treatment pay off?

  • Because short codes are less error-prone, so the most common letter should be the best protected.
  • Because "e" is the most important letter and important letters should arrive first.
  • Because it makes the average message shorter: what occurs often then costs little.
  • Because an alphabet with codes of different lengths can hold more letters than one with equal lengths.

A link can reliably manage only two symbols, bright and dark. It is still supposed to transmit an alphabet of 32 characters by grouping several flashes. How many flashes does one group need at least?

  • 16, half the number of characters.
  • 5, because two to the fifth is 32.
  • 32, because every character needs one flash.
  • 6, because one extra place is needed to separate the groups.

Download with answers: CSV Anki

Further reading

Claude E. Shannon: "A Mathematical Theory of Communication". Bell System Technical Journal 27, 1948. The paper the bit, uncertainty as a logarithm and the limit of every compression come from; its first pages get by with little mathematics, and Claude Shannon tells how it came about.

James Gleick: The Information: A History, a Theory, a Flood. Pantheon, 2011. A history of information from the talking drums of Africa through the telegraph to Shannon, easy to read and free of formulas.

Back
More on this
Details
Level
Beginner
Modules
Digitization and Programming
Code
3134
Updated
4 November 2026
Status
published

    A four-digit code takes you straight to the item.