Shannon-Fano coding


Definition: A variable-length coding based on the frequency of occurrence of each character. Divide the characters into two sets with the frequency of each set as close to half as possible, and assign the sets either 0 or 1 coding. Repeatedly divide the sets until each character has a unique coding.

See also arithmetic coding, Huffman coding, Zipf's law.

Note: Shannon-Fano is a minimal prefix code. Huffman is optimal for character coding (one character-one code word) and simple to program. Arithmetic coding is better still, since it can allocate fractional bits, but is more complicated and has patents.

Author: PEB

More information

Debra A. Lelewer's and Daniel S. Hirschberg's survey of data compression.

Go to the Dictionary of Algorithms and Data Structures home page.

If you have suggestions, corrections, or comments, please get in touch with Paul Black.

Entry modified 4 January 2005.
HTML page formatted Wed Mar 13 12:42:46 2019.

Cite this as:
Paul E. Black, "Shannon-Fano coding", in Dictionary of Algorithms and Data Structures [online], Paul E. Black, ed. 4 January 2005. (accessed TODAY) Available from: