ArticleslgStudy

science

Shannon–Fano coding

Shannon–Fano coding is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Shannon–Fano coding rather than just read about it. In short: In the field of data compression, Shannon–Fano coding, named after Claude Shannon and Robert Fano, is one of two related techniques for constructing a prefix code based on a set of symbols and their probabilities (estimated or measured). Shannon's method chooses a prefix code where a source symbol i {\displaystyle i} is given the codeword length l i = ⌈ − log 2 ⁡ p i ⌉ {\displaystyle l_{i}=\lceil -\log _{2}p_{i}\rce…

Shannon–Fano coding — main illustration
Shannon–Fano coding — illustration

Key takeaways

  • Shannon–Fano coding belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Shannon–Fano coding to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Shannon–Fano coding from memory before moving on to harder problems.

Reference excerpt

In the field of data compression, Shannon–Fano coding, named after Claude Shannon and Robert Fano, is one of two related techniques for constructing a prefix code based on a set of symbols and their probabilities (estimated or measured).

Shannon's method chooses a prefix code where a source symbol i {\displaystyle i} is given the codeword length l i = ⌈ − log 2 ⁡ p i ⌉ {\displaystyle l_{i}=\lceil -\log _{2}p_{i}\rceil } . One common way of choosing the codewords uses the binary expansion of the cumulative probabilities. This method was proposed in Shannon's "A Mathematical Theory of Communication" (1948), his article introducing the field of information theory. Fano's method divides the source symbols into two sets ("0" and "1") with probabilities as close to 1/2 as possible. Then those sets are themselves divided in two, and so on, until each set contains only one symbol. The codeword for that symbol is the string of "0"s and "1"s that records which half of the divides it fell on. This method was proposed in a later (in print) technical report by Fano (1949). Shannon–Fano codes are suboptimal in the sense that they do not always achieve the lowest possible expected codeword length, as Huffman coding does. However, Shannon–Fano codes have an expected codeword length within 1 bit of optimal. Fano's method usually produces encoding with shorter expected lengths than Shannon's method. However, Shannon's method is easier to analyse theoretically. Shannon–Fano coding should not be confused with Shannon–Fano–Elias coding (also known as Elias coding), the precursor to arithmetic coding.

Naming Regarding the confusion in the two different codes being referred to by the same name, Krajči et al. write:

Around 1948, both Claude E. Shannon (1948) and Robert M. Fano (1949) independently proposed two different source coding algorithms for an efficient description of a discrete memoryless source. Unfortunately, in spite of being different, both schemes became known under the same name Shannon–Fano coding. There are several reasons for this mixup. For one thing, in the discussion of his coding scheme, Shannon mentions Fano’s scheme and calls it “substantially the same” (Shannon, 1948, p. 17 [reprint]). For another, both Shannon’s and Fano’s coding schemes are similar in the sense that they both are efficient, but suboptimal prefix-free coding schemes with a similar performance.

Shannon's (1948) method, using predefined word lengths, is called Shannon–Fano coding by Cover and Thomas, Goldie and Pinch, Jones and Jones, and Han and Kobayashi. It is called Shannon coding by Yeung. Fano's (1949) method, using binary division of probabilities, is called Shannon–Fano coding by Salomon and Gupta. It is called Fano coding by Krajči et al.

Shannon's code: predefined word lengths

Shannon's algorithm Shannon's method starts by deciding on the lengths of all the codewords, then picks a prefix code with those word lengths. Given a source with probabilities p 1 , p 2 , … , p n {\displaystyle p_{1},p_{2},\dots ,p_{n}} the desired codeword lengths are l i = ⌈ − log 2 ⁡ p i ⌉ {\displaystyle l_{i}=\lceil -\log _{2}p_{i}\rceil } . Here, ⌈ x ⌉ {\displaystyle \lceil x\rceil } is the ceiling function, meaning the smallest integer greater than or equal to x {\displaystyle x} . Once the codeword lengths have been determined, we must choose the codewords themselves. One method is to pick codewords in order from most probable to least probable symbols, picking each codeword to be the lexicographically first word of the correct length that maintains the prefix-free property. A second method makes use of cumulative probabilities. First, the probabilities are written in decreasing order p 1 ≥ p 2 ≥ ⋯ ≥ p n {\displaystyle p_{1}\geq p_{2}\geq \cdots \geq p_{n}} . Then, the cumulative probabilities are defined as

c 1 = 0 , c i = ∑ j = 1 i − 1 p j for i ≥ 2 , {\displaystyle c_{1}=0,\qquad c_{i}=\sum _{j=1}^{i-1}p_{j}{\text{ for }}i\geq 2,}

… excerpt ends here. Continue reading the full article.

Illustrations

Shannon–Fano coding: Huffman Algorithm
Huffman Algorithm

Worked examples

Example 1 — a first encounter with Shannon–Fano coding

Start with the simplest possible case. Write down what Shannon–Fano coding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Shannon–Fano coding before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Shannon–Fano coding ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Shannon–Fano coding

In research
Shannon–Fano coding appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Shannon–Fano coding in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Shannon–Fano coding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Claude Shannon, Data compression, Entropy coding, so understanding it makes those chapters shorter.
In everyday life
Look for Shannon–Fano coding outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Shannon–Fano coding” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Shannon–Fano coding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Shannon–Fano coding means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Shannon–Fano coding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Shannon–Fano coding in simple terms?

In the field of data compression, Shannon–Fano coding, named after Claude Shannon and Robert Fano, is one of two related techniques for constructing a prefix code based on a set of symbols and their probabilities (estimated or measured). Shannon's method chooses a prefix code where a source symbol…

Why does Shannon–Fano coding matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Shannon–Fano coding?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Shannon–Fano coding.

Tags

  • Claude Shannon
  • Data compression
  • Entropy coding

Keep exploring