GCSE · Computer Science · AQA · Spec 8525

Huffman coding bit calculations

Same text, two sizes. One spends a flat 7 bits per character; the other gives common characters tiny codes. Count both.

Computer Science · Data compression

Mississippi, one character at a time

The codes are already read off the tree. Step through and watch the running total grow.

Watch the running total. Which character ends up costing the most bits?

1 Start the running total at 0 bits
2 For each character: bits used = frequency × code length
3 Add those bits to the running total
4 ASCII size = number of characters × 7
5 Bits saved = ASCII size − Huffman total
CharacterFrequencyCodeCode lengthBits usedRunning total
–––––0

Output

 

Step 1: The text is Mississippi: 11 characters. We start at 0 bits and build the total one character at a time.

1 / 7

Use Next to add one character at a time. Say each number out loud: what does it count?

Step 1 of 7: The text is Mississippi: 11 characters. We start at 0 bits and build the total one character at a time..

Exam line: Show frequency × code length for every character, add them up, then compare with characters × 7.
Watch out: Multiply by how many times each character appears. Adding each code length once gives a total that is far too small.

Computer Science · Data compression

Which idea sounds like yours?

Mississippi has 11 characters. Huffman coding stores it in 21 bits, and 7-bit ASCII stores it in 77 bits.

Which idea is closest to what you think right now?
How sure are you?

Exam line: Multiply by frequency, use 7 bits per ASCII character unless the question states another figure, and keep the tree out of the compressed total.

Computer Science · Data compression

How small can hello get?

The word hello has 5 characters, so 7-bit ASCII needs 5 × 7 = 35 bits. Huffman coding gives the repeated L a very short code. Slide to your estimate: how many bits does the Huffman-coded hello need?

Your estimate

18 bits

0 bits35 bits

Exam line: Compare the two sizes at the end: the compressed total should come out smaller than characters × 7.

Computer Science · Data compression

Now you finish hello

Work out how many bits Huffman coding saves on the text hello. Codes: L = 0, O = 10, H = 110, E = 111.

  1. Frequencies: L 2, O 1, H 1, E 1 (5 characters in total)
  2. L: 2 × 1 = 2 bits
  3. missing step
Which line is step 3?

Exam line: Same four moves on any text: one product per character, add, size in ASCII, subtract.

Computer Science · Data compression

Where did this working go wrong?

The text banana is stored using Huffman coding. Frequencies: A 3, N 2, B 1. Codes: A = 0, N = 10, B = 11. How many bits does Huffman coding save compared with 7-bit ASCII?

A student's working — which line goes wrong?

Exam line: Check every character's row is frequency × code length before you add anything up.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Multiply, add, compare with ASCII, and see how many bits you save.

What you need to know

  • Huffman coding gives frequent characters short bit patterns, so they stay cheap however often they appear.
  • Every time a character appears, it costs the full length of its code, read from the Huffman tree.
  • Have a goYour mate Sam says: 'E appears 6 times and its code is 2 bits long, so E costs 2 bits.' How many bits does E really cost?

    12 bits (6 × 2).

    Sam counted the code once. Every appearance of E is stored using its whole code, so you pay the 2 bits six times.

  • So the compressed total is frequency × code length for each character, all added together.
  • AQA 8525 counts ASCII at 7 bits per character: uncompressed size is the number of characters × 7, repeats included.
  • Have a goFinish the sentence: the ASCII size in bits is the number of ___ (repeats included) multiplied by ___.

    characters; 7.

    Repeated characters are still characters, and ASCII here is 7 bits each, not 8.

  • If a question itself states a different number of bits per character, use that figure for that question only.
  • Bits saved = ASCII size − Huffman total. Big minus small.
  • Have a goHuffman coding gives 18 bits and the ASCII size is 35 bits. Which way round do you subtract, and what is the saving?

    35 − 18 = 17 bits saved.

    The saving is the bigger ASCII size minus the smaller Huffman total; 18 − 35 would give a negative number.

  • The tree isn't counted in the compressed total, but it must be kept or sent, which adds overhead.
  • In these questions the codes are handed to you. Only the length of each code matters.

The big picture

Huffman coding stores common characters in short bit patterns. To count the compressed size you multiply each character's frequency by its code length and add the results. Compare that with the ASCII size (characters × 7) and the difference is the number of bits saved.

Key points

1Compressed bits = frequency × code length for each character, added together.
2ASCII size = number of characters × 7 bits (repeats included), unless a question states a different figure.
3Bits saved = ASCII size − Huffman total.
4The tree isn't in the compressed total, but it must be kept or sent for decompression, so it adds overhead.

Worked example

Problem

A question states that each character is stored using 8 bits. The text mama has 4 characters: M appears 2 times (code 0) and A appears 2 times (code 1). How many bits does Huffman coding save?

⚠ Watch out

Adding each code length once instead of multiplying by frequency, using 8 bits per ASCII character, or adding the tree to the compressed total.

🧠

Memory hook

Times it, then add it: frequency × length. Seven bits for ASCII. Big minus small for the saving.

✓

Check yourself

Try aabc: a twice (code 0), b once (10), c once (11). Find the Huffman total, ASCII size and saving. Answer: 6, 28, 22 bits.

Flashcards

(10)
Huffman total: what do you do for each character?
Multiply its frequency by its code length (the number of bits in its code), then add the results for all the characters.
Why multiply by the frequency?
Each time a character appears, its whole code is stored again, so it costs its code length every time.
How many bits is one ASCII character in AQA 8525?
7 bits.
Uncompressed ASCII size, in bits?
Number of characters × 7. Count repeated characters too.
How do you find the bits saved by Huffman coding?
ASCII size − Huffman-coded total. Big number minus small number.
A question states a different number of bits per character. What do you do?
Use the stated figure, for that question only.
Is the Huffman tree counted in the compressed bit total?
No. The total is the raw compressed size only. But the tree must be kept or sent for decompression, which adds overhead.
Where does a character's code length come from?
The Huffman tree: it is the number of bits in that character's code. Only the length matters for the calculation.
Mississippi: what does the row 4 × 2 = 8 stand for?
I appears 4 times, and each appearance costs its 2-bit code (10).
Why is a frequent character with a short code cheap overall?
It appears often, but every appearance costs only a few bits.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 24 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.