โ† Back to all tools

๐Ÿ“ฆ How Do Computers Shrink Files? โ€” Compression Explained

See how Run-Length Encoding (RLE) and Huffman coding compress data โ€” with every step shown.

Designed with the WJEC specification in mind
CS GCSE ยง1.2.1DigiTech GCSE ยง1.1.2

๐Ÿค” What is compression?

Compression is making files smaller so they take up less space and transfer faster. Like packing a suitcase efficiently, computers use clever tricks to squeeze data into less room without losing important information.

๐Ÿ• Analogy: Imagine describing "AAAAAABBBB" to a friend. Instead of saying each letter, you could say "6 A's then 4 B's" โ€” that's compression!
๐Ÿ“ Run-Length Encoding
๐ŸŒณ Huffman Coding
๐Ÿ“– Key Concepts
๐Ÿ“

Run-Length Encoding

RLE replaces consecutive repeated characters with a count + character pair. Works best when data has long runs of the same value.

๐ŸŒณ

Huffman Coding

Huffman coding assigns shorter codes to more frequent characters. It's a variable-length, lossless compression technique.

๐Ÿ“–

Lossy vs Lossless Compression

โœ… Lossless

  • Original data can be perfectly restored
  • No quality loss
  • Examples: ZIP, PNG, FLAC, RLE, Huffman
  • Used for: text, code, spreadsheets

โš ๏ธ Lossy

  • Some data is permanently removed
  • Smaller files but quality loss
  • Examples: JPEG, MP3, MP4, AAC
  • Used for: photos, music, video
๐Ÿ’ก

When to use which?

RLE works best when data has many consecutive repeated values (e.g. simple graphics, fax documents). It can actually make data larger if there are few repeats.

Huffman coding works well when some characters appear much more often than others. The more skewed the frequency distribution, the better the compression.

Compression ratio = original size รท compressed size. Higher = better compression.

๐Ÿ“

Exam Tips

  • GCSE: Be able to explain the difference between lossy and lossless compression with examples
  • A-Level: Know how to calculate compression ratios and when each algorithm works best
  • Key point: RLE can make files larger if there are few repeated characters
  • Remember: Use lossless for text/code, lossy for media (photos/music/video)