L
LLLOS.ai
Learn
L

Ask Your Tutor · Computer Science

How does file compression actually work inside a computer?

From NCERT In depth Asked by Anonymous from Bordeaux, France 23 Oct 2026, 7:15 PM IST Updated

In one line

File compression means making a file smaller by removing repeated or unnecessary parts, so it takes up less space.

The rule

File compression is the process of encoding information using fewer bits than the original representation, reducing file size for storage or transmission.

There are two main types:

  • Lossless compression: No information is lost; you can get back the exact original file.
  • Lossy compression: Some information is lost; you get a smaller file, but not exactly the same as the original.

Let's understand it simply

Imagine you are packing your school bag. If you just throw everything in, it takes up a lot of space. But if you fold your clothes, stack your books neatly, and remove things you don't need, you can fit much more. File compression does the same for data. It finds patterns and repeats, folds them up, and removes extra bits, so the file becomes smaller. When you want to use the file again, the computer "unfolds" it back to normal.

Lossless vs Lossy Compression
LosslessLossy
What happensNo information lostSome information lost
ExamplesZIP, PNG, FLACJPEG, MP3, MP4
Can you get original back?Yes, exactlyNo, only similar

How it works

  1. Find patterns or repeats: The computer looks for repeated words, numbers, or data (like 'AAAAAA').
  2. Replace repeats with short codes: Instead of writing 'AAAAAA', it writes '6A' (meaning six A's).
  3. Remove unnecessary data: For lossy compression (like in photos), it throws away tiny details our eyes can't see.
  4. Store or send the smaller file: The compressed file is saved or sent over the internet.
  5. Decompress when needed: When you open the file, the computer reads the codes and rebuilds the original data.
How File Compression Works
  1. Find repeated data or patterns
  2. Replace repeats with short codes
  3. Remove extra or unnecessary details (for lossy)
  4. Store or send the smaller file
  5. Decompress to get the original back

The story behind it

The idea of compression started with telegraphs and early computers, where every bit of space and speed mattered. In 1948, Claude Shannon, an American mathematician, created the theory of information, showing how to measure and reduce data. Later, scientists made algorithms (step-by-step methods) like Huffman coding (1952) and Lempel-Ziv (1977), which are still used in ZIP files and images today. The need to send more data over slow lines and store more in tiny chips made compression very important.

Where you see it in real life

  • ZIP files: When you download a project as a .zip, it is compressed to save space and time.
  • Photos on your phone: JPEG images are compressed, so you can store thousands of pictures.
  • WhatsApp voice messages: Audio is compressed, so it sends quickly even with slow internet.
  • YouTube videos: Videos are compressed so you can watch them without waiting for hours.
  • PDFs and documents: Scanned pages are compressed to make files easy to email.
  • Apps and games: Installers are compressed to fit on your phone or pen drive.

Why it matters

  • Saves storage: You can keep more files on your phone, computer, or memory card.
  • Faster sharing: Smaller files upload and download much quicker, even on slow networks.
  • Reduces costs: Less data means lower internet bills and cheaper cloud storage.
  • Needed for streaming: Without compression, watching movies or listening to music online would be almost impossible.

Worked example

Let's see how a simple text file is compressed using a basic method called Run-Length Encoding (RLE):

Original text:  AAAABBBCCDAA
Step 1: Find repeats: 4 A's, 3 B's, 2 C's, 1 D, 2 A's
Step 2: Write as codes: 4A 3B 2C 1D 2A
Step 3: Compressed text: 4A3B2C1D2A
Step 4: To decompress, expand each code: AAAABBBCCDAA

Common mistakes

  • Thinking all compression is lossless: Some types (like JPEG, MP3) lose details you can't get back.
  • Assuming compression always works: Some files (already compressed or random data) can't be made smaller.
  • Forgetting to decompress: You can't use a compressed file directly; you must extract or open it first.
  • Confusing file types: Not all small files are compressed; some are just simple or short.

Remember it

File compression is like folding clothes to fit more in your bag — it saves space by finding patterns and packing data tightly.

Check yourself

What is the main purpose of file compression?

To reduce the size of files so they take up less space and are faster to send.

Why can't you always get back the exact original file after lossy compression?

Because lossy compression removes some details permanently to save more space.

Give one example of a lossless and one of a lossy compression format.

Lossless: ZIP; Lossy: JPEG.

Why does WhatsApp compress voice messages before sending?

To make the file smaller so it sends quickly, even on slow networks.

Quick recap

  • File compression makes files smaller by finding patterns and removing extra data.
  • There are two types: lossless (no data lost) and lossy (some data lost).
  • Compression saves storage space and makes sharing files faster.
  • You must decompress files to use them in their original form.
  • Not all files can be compressed further, especially if they are already compressed.
Written by the LLOS.ai tutor, checked against NCERT chapters. Asked by Anonymous from Bordeaux, France on 23 Oct 2026, 7:15 PM IST