Data Compression Formula

Data compression is the process of reducing the number of bits needed to store or transmit information.

The Formula

compression ratio=original sizecompressed size

Ask yourself: Is the same information being stored in fewer bits, either recoverable exactly or with some detail thrown away?

Quick example

A text file can often be compressed losslessly, while a photo may be compressed with JPEG by discarding detail the human eye notices less.

What this formula means

Data compression is the process of reducing the number of bits needed to store or transmit information. Some compression is lossless, meaning the original data can be recovered exactly, while some is lossy, meaning some detail is discarded to save more space.

Compression is packing a suitcase. Lossless is rolling and folding: everything you packed comes out again, just in less space. Lossy is leaving things at home that you probably will not miss; the bag gets much lighter, but those things are not there when you unpack.

Formal view

Compression maps a source message to a shorter code representation. Lossless methods preserve exact decoding; lossy methods accept some distortion to reduce size further.

Worked examples

Example 1

medium
Apply RLE to `XYZXYZXYZ`. Is the result shorter? Explain.
Show solution

Answer

1X1Y1Z1X1Y1Z1X1Y1Z (longer)

First step

1.
Each character forms its own run of length 1.

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Free: full solutions on 3 topics a day. No card.

Every topic, every day: the Family plan

Example 2

medium
In Huffman coding, symbol A has frequency 0.5, B has 0.25, C and D each 0.125. Assign reasonable code lengths in bits.

Example 3

medium
You must transmit medical X-ray images. Which compression type is appropriate and why?

Common mistakes

  • Assuming every compressed file can be restored perfectly
  • Ignoring the quality loss caused by repeated lossy compression
  • Comparing compressed files without checking whether they use the same format and settings

Common mistakes guide

If this formula keeps breaking in real problems, read the most common errors before you practice again.

Why this formula matters

A 3-minute song stored as CD audio takes about 32 MB; as an MP3 it takes about 3 MB, which is why a phone holds thousands of songs and a video call fits through home internet. Knowing which kind of compression you are using tells you what is safe: you can zip and unzip a document forever, but every re-save of a JPEG loses a little more.

Frequently asked questions

What is the Data Compression formula?

Data compression is the process of reducing the number of bits needed to store or transmit information. Some compression is lossless, meaning the original data can be recovered exactly, while some is lossy, meaning some detail is discarded to save more space.

How do you use the Data Compression formula?

Think compression when a problem is about file size, storage space, upload time or bandwidth, or asks whether the original can be restored. If every bit must come back (text, program code, spreadsheets, bank records), choose lossless. If a smaller file matters more than perfect detail (photos, music, video), lossy is acceptable. If the question is about hiding data from other people, that is encryption; if it is about how a letter or pixel becomes bits in the first place, that is data representation.

Why is the Data Compression formula important in CS Thinking?

A 3-minute song stored as CD audio takes about 32 MB; as an MP3 it takes about 3 MB, which is why a phone holds thousands of songs and a video call fits through home internet. Knowing which kind of compression you are using tells you what is safe: you can zip and unzip a document forever, but every re-save of a JPEG loses a little more.

What do students get wrong about Data Compression?

Smaller is not always better. You must decide whether exact recovery matters.

What should I learn before the Data Compression formula?

Before studying the Data Compression formula, you should understand: bits bytes, data representation.