AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    Data compression: Explain how data can be compressed using Huffman coding.

    Huffman coding is a lossless method that gives shorter binary codes to more frequently occurring characters and longer codes to rarer ones, so the total number of bits falls.

    Checked against the AQA 8525 specification (opens in a new tab) on .

    • Point 4 of 13

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Huffman coding is a lossless method that gives shorter binary codes to more frequently occurring characters and longer codes to rarer ones, so the total number of bits falls. Learners should be able to explain the process: count how often each character appears, repeatedly combine the two lowest-frequency items into a node whose frequency is their sum, and continue until a single tree remains. Reading the tree from root to leaf, assigning 0 to one branch and 1 to the other, produces each character's code. A concrete example helps: if one character appears far more often than others, it ends up near the root with a short code, while a rare character sits deep in the tree with a long code. Because no code is a prefix of another, the original data can be reconstructed exactly, which is why Huffman coding is lossless.

    What earns the marks

    • Huffman coding is a lossless compression method, so the original data can be reconstructed exactly.
    • More frequent characters are assigned shorter binary codes and less frequent characters longer codes, reducing total bits.
    • The method builds a tree by repeatedly combining the two lowest-frequency nodes until one root remains.
    • Codes are read from the tree by labelling branches (for example 0 and 1) from root to leaf.
    • No code is a prefix of another, allowing unambiguous decoding of the compressed data.

    Common mistakes and how to put them right

    • Assigning the shortest code to the rarest character.

      Put it right: Is that the most frequent character gets the shortest code.

    • Treating Huffman coding as lossy.

      Put it right: Is that it is lossless and allows exact reconstruction.

    • Combining arbitrary nodes rather than the two lowest-frequency ones.

      Put it right: Is that the two lowest-frequency items are merged at each step.

    Exam tips

    • Show the frequency counting and the merging steps in order so the tree-building process is visible.
    • State clearly that frequent characters get short codes and explain why this reduces total bits.
    • Mention that the method is lossless and that prefix-free codes allow decoding.

    Try the lesson

    The start of the Data compression: Explain how data can be compressed using Huffman coding. lesson, made from checked teaching notes for this specification point.

    Have a go first

    In Huffman coding, what is done to the character that appears most frequently in the data?

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Test your understanding of Data compression: Explain how data can be compressed using Huffman coding.

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge