Information Measures and Source Coding
Every communication system must answer two questions: how much can a message be compressed without losing anything, and how fast can information be sent over a noisy medium? Claude Shannon's 1948 work showed that both questions have precise answers, and that those answers depend on a single quantity: how much a source is uncertain about its next output. This article introduces the measures that capture that uncertainty, namely self-information, entropy, and mutual information. It then uses them to state the source coding theorem, which gives the fundamental limit on lossless compression, and to build Huffman codes, which reach that limit closely in practice.
Surprise and Self-Information
Information, in Shannon's sense, is tied to surprise. If a weather forecast says "sunny in the Sahara," you learn almost nothing, because you expected it. If it says "snow in the Sahara," you learn a great deal. The less probable an outcome, the more information its occurrence conveys.
For an event with probability , the self-information is defined as
The base-2 logarithm makes the unit the bit: one bit is the information in a fair coin toss. The logarithm is chosen so that information from independent events adds, since probabilities multiply. A certain event with carries zero information, and an event with very small carries a large amount. The curve below shows how quickly self-information grows as probability shrinks.
Self-information describes a single outcome. A source produces a stream of outcomes, and what matters for compression is the typical amount of information per symbol. Averaging self-information over all outcomes leads directly to entropy, which is the subject of the next section.
Entropy as the Average Uncertainty of a Discrete Source
Consider a discrete memoryless source that emits symbols with probabilities . The entropy of the source is the expected self-information of its output:
Entropy is the average number of bits needed to describe a symbol once the source statistics are known. It is zero when one symbol is certain, because then there is nothing to decide. It is largest when all symbols are equally likely, in which case . This maximum is the reason uniform sources are the hardest to compress.
The binary case shows the shape of this behaviour clearly. For a source with two symbols, of probabilities and , the entropy is the binary entropy function . It peaks at 1 bit when and falls to zero at the extremes.
Entropy is a property of the source alone, not of any code. It sets the benchmark against which every code is measured. A code that uses fewer bits per symbol on average than is impossible to construct for lossless compression, and this is the content of the source coding theorem below.
Joint, Conditional, and Average Mutual Information
Real systems involve two random variables at once, such as an input and an output of a channel, or a pixel and its neighbour. The joint entropy measures the uncertainty of the pair. The conditional entropy measures the uncertainty left in after is known. These are linked by the chain rule .
The central quantity is the average mutual information, which measures how much knowing reduces the uncertainty about :
Mutual information is symmetric, so . It is zero when and are independent, because then knowing tells you nothing about . It never exceeds . The Venn-style picture below summarises how these quantities relate.
This is the bridge to channel coding. When is the transmitted symbol and the received symbol, the mutual information measures how much of the message survives the channel. Maximising this quantity over input distributions leads to channel capacity, which is covered in the module on channel models and capacity.
Information Measures for Continuous Random Variables
Many sources, such as speech samples or sensor readings, take values in a continuum. The natural extension of entropy replaces the sum with an integral over a probability density . This quantity is called differential entropy:
Differential entropy behaves differently from discrete entropy in two important ways. It can be negative, since a density can exceed 1 over a narrow range. It also changes under scaling: , so it is not an absolute measure of uncertainty in the way is. The mutual information between continuous variables, however, remains non-negative and invariant under such changes, which is why it, rather than differential entropy alone, is the quantity that carries operational meaning.
For a Gaussian random variable with variance , the differential entropy takes a particularly clean form, and among all densities with a given variance it is the largest. This is the reason the Gaussian appears as the worst-case noise in the capacity results that follow in the channel module. The detailed derivations, the scaling properties, and the relation to discrete entropy as a quantised limit belong to the dedicated article on this topic.
The Source Coding Theorem
A source code maps each source symbol to a binary string, called a codeword. The code is useful only if the original message can be recovered from the encoded bits. The class that is practical for real-time decoding is the prefix code, in which no codeword is the beginning of another. Prefix codes can be decoded instantly, reading bits until a complete codeword appears.
If a symbol receives a codeword of length , the average codeword length is . Shannon's source coding theorem states that for a discrete memoryless source, the best achievable average length satisfies
The lower bound is a hard limit: no lossless code can average fewer bits per symbol than the entropy. The upper bound says that a good code is never more than one bit per symbol above the limit. The gap of less than one bit can be reduced further by coding blocks of several symbols together, so that the average length per symbol approaches as the block length grows. Whether a prefix code with given lengths exists at all is governed by the Kraft inequality, which is developed in the child article.
The theorem makes entropy an operational quantity. It is not merely a formula for average surprise but the exact compression limit for lossless coding. The next section shows a practical construction that comes very close to this limit.
Huffman Codes and Their Efficiency
Huffman coding builds an optimal prefix code for a known set of symbol probabilities. The idea is greedy and easy to state. Repeatedly take the two least probable symbols, merge them into a single node whose probability is their sum, and continue until one node remains. Reading the branch labels from the root to each leaf then gives the codewords. Frequent symbols end up near the root with short codewords, and rare symbols end up deep in the tree with long ones.
Take a source with symbols A, B, C, D having probabilities 0.4, 0.3, 0.2, 0.1. Merging C and D gives 0.3, then merging B with that node gives 0.6, and finally merging A with that gives 1. The resulting codewords are A = 0, B = 10, C = 110, D = 111. The average length is bits per symbol. The entropy is approximately 1.846 bits, so the bound holds.
The efficiency of a code is , which here is about 97 percent. The remaining gap is the redundancy , about 0.054 bits per symbol. Huffman's method is optimal among symbol-by-symbol prefix codes, meaning no other such code achieves a smaller average length for the same distribution. Its limitation is that it needs the probability model in advance, and it cannot beat the one-bit gap without grouping symbols into blocks. Adaptive and arithmetic methods address these limitations, and the child article details the construction, the proof of optimality, and the choice of blocks.