Technologies K–10 · Years 9–10
Run-length encoding: when compression makes a file smaller and when it does not
Computing Technology 7–10 (NSW, 2022); Digital Technologies: Knowledge and understanding, Data representation (ACARA v9)
This site has no interactive model of its own. Where a step or a material names a Concept Studio model, simulation or tool, it has not been built; an external simulation a step names (for example PhET) is not part of this site.
The idea
Run-length encoding replaces each run of identical pixels with its length, which shrinks images with long runs and can enlarge busy ones, so the benefit of a compression technique depends on the data.
What you need
- Grid paper; the 8 × 8 smiley code (00111100, 01000010, 10100101, 10000001, 10100101, 10011001, 01000010, 00111100)
- A 64 × 64 test image: white with a centred black square 16 pixels wide (rows and columns 24 to 39)
- Computer with Python 3
How to do it
- Encode each smiley row as run lengths, starting with the number of white pixels (0 if the row starts black).
- Count the run numbers. Each number from 0 to 8 needs 4 bits; work out the encoded size and compare with 64 bits.
- Encode the 64 × 64 square image the same way; run lengths up to 64 need 7 bits each.
- Write a Python function that encodes a row of 0s and 1s and a second that decodes it; check that decoding returns the original exactly.
- Explain which kinds of image suit run-length encoding and why fax machines used it.
What you should see
The smiley gives 42 run numbers, 168 bits at 4 bits each: 2.625 times the 64 raw bits, so encoding makes it bigger. The square image gives 96 run numbers (one for each of the 48 all-white rows and three for each of the 16 rows through the square), 672 bits at 7 bits each against 4,096 raw bits, 6.1 times smaller. Decoding returns the exact original in both cases, so run-length encoding is lossless. The learner knows it worked when their hand counts match the program's and the decoder rebuilds both images exactly.
What changes
This activity lists no variables to change, measure and keep the same.
Common misconceptions
Each of these ideas is wrong, and the activity is a chance to test it.
- Compression always makes files smaller (busy data can grow).
- Compressed files lose detail (lossless methods such as run-length encoding rebuild the data exactly).
- The same method suits all data (long runs suit run-length encoding; photographs rarely have them).
Safety card
Hazards
- None beyond normal computer use
Controls
- Not applicable
Note
No chemicals or heat.
Curriculum references
The NSW syllabus outcomes and Australian Curriculum v9 codes this activity supports. They are references, not a verified or complete curriculum alignment.
- Computing Technology 7–10 Syllabus (2022), NESA. Current elective syllabus. Code read from the outcomes page on 2026-09-22.CT5-DAT-01
- Australian Curriculum v9AC9TDI10K03
Sources
The pages the author read to write this activity.