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 bits2 For each character: bits used = frequency × code length3 Add those bits to the running total4 ASCII size = number of characters × 75 Bits saved = ASCII size − Huffman total
| Character | Frequency | Code | Code length | Bits used | Running 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.
Use Next to add one character at a time. Say each number out loud: what does it count?
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
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?
Why multiply by the frequency?
How many bits is one ASCII character in AQA 8525?
Uncompressed ASCII size, in bits?
How do you find the bits saved by Huffman coding?
A question states a different number of bits per character. What do you do?
Is the Huffman tree counted in the compressed bit total?
Where does a character's code length come from?
Mississippi: what does the row 4 × 2 = 8 stand for?
Why is a frequent character with a short code cheap overall?
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 postedMore AQA GCSE Computer Science topics
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.