Let and let be the probability cell of symbol . Its midpoint is . Use the binary expansion terminating in zeros at a dyadic rational, so truncation to bits gives
The chosen codeword corresponds to the dyadic interval . It contains , and its width satisfies . Consequently
Thus . The probability cells are disjoint, so the code intervals are disjoint. If one binary codeword were a prefix of another, its dyadic interval would contain the other's interval, contradicting this disjointness. Hence the code is instantaneous.
Finally, . Multiplying by and summing yields
This is the Shannon-Fano-Elias code: the extra bit makes the dyadic interval narrow enough to remain inside the cell around its midpoint.
Figure 1. . An original example with probabilities two fifths, three tenths, one fifth, and one tenth. Each orange dyadic code interval contains its black midpoint and lies inside its blue probability cell, proving that the displayed codewords cannot be prefixes of one another. Details.
Shannon-Fano-Elias code 2026-10-31
For positive source probabilities in a fixed order, let and . The Shannon-Fano-Elias code uses the first binary digits of the midpoint , using the terminating-zero expansion at dyadic rationals. Its dyadic interval contains and has width at most , so it lies inside the probability cell . These cells are disjoint, whereas a codeword that is a prefix of another has a dyadic interval containing the other interval. The code is therefore a prefix code. Since , averaging proves . This is a direct cumulative construction and does not require sorting the probabilities or constructing a Huffman tree.