ABK TechnologiesPractical technology for real-world impact

How Does a 1 GB Folder Become a 400 MB ZIP File? The Science Behind Data Compression

October 26, 2026 · 7 min read

Imagine you have a folder containing 1 GB of photos, documents, videos, or other files. You compress it into a ZIP archive, and suddenly, the file is only 400 MB.

You have saved 600 MB of storage space.

But here’s the interesting part: when you unzip the archive, you get all your original files back.

Where did those 600 MB go?

Did the computer delete some data? Did it sacrifice quality? Or did it discover a smarter way to store the same information?

The answer lies in a fascinating computer science concept called data compression. One of the algorithms that helps explain how this works is Huffman coding.

Let’s break it down.

1. Your Computer Stores Information as Bits

At its most fundamental level, a computer represents information using binary digits, or bits. Each bit is either a 0 or a 1.

Text, images, audio, and other digital information are represented using sequences of these bits.

For example, a common text encoding such as ASCII represents each character using 8 bits.

Consider the word:

BANANA

It contains six letters. If each letter occupies 8 bits, the word requires:

6 × 8 = 48 bits.

However, look more closely at the word:

  • B appears once.
  • A appears three times.
  • N appears twice.

The letter A is repeated three times, yet a conventional fixed-width representation gives every occurrence the same amount of space.

Could we represent frequently occurring letters using fewer bits?

Yes. That is the basic intuition behind Huffman coding.

2. The Big Idea: Represent Repeated Information More Efficiently

Imagine assigning these binary codes to the letters:

Now let’s encode BANANA.

Putting the codes together gives us:

100110110

Count the bits. We have only 9 bits instead of 48.

That’s a substantial reduction in this simplified example.

Notice something important: we haven’t removed any letters. We’ve changed how we represent them.

The original information remains intact.

However, these particular codes are an illustrative example, not necessarily the optimal encoding for every dataset. Huffman coding provides a systematic way to construct efficient variable-length codes based on how frequently symbols occur.

3. Meet Huffman Coding

Huffman coding is a lossless data compression algorithm developed by computer scientist David A. Huffman in 1952.

Its central principle is straightforward:

Frequently occurring symbols should generally receive shorter binary codes, while less frequent symbols receive longer codes.

This can reduce the total number of bits required to represent a dataset.

Let’s see how it works using BANANA.

Step 1: Count the frequency of each letter

Our word contains three distinct letters.

The letter A occurs most frequently, while B occurs least frequently.

Step 2: Combine the two least frequent symbols

Huffman coding starts by combining the two symbols or groups with the lowest frequencies.

B has a frequency of 1, and N has a frequency of 2.

Combine them:

1 + 2 = 3.

We now have two groups:

  • A, with a frequency of 3.
  • The combined B–N group, with a frequency of 3.

Step 3: Combine the remaining groups

Next, combine these two groups:

3 + 3 = 6.

The resulting structure is called a Huffman tree.

The root represents the total frequency of all six letters. One branch leads to A, while the other leads to the group containing B and N.

Step 4: Assign binary codes

Label the left branches 0 and the right branches 1.

The resulting codes can be:

  • A = 0
  • B = 10
  • N = 11

To reach A, we take one left branch, giving us 0.

To reach B, we go right and then left, giving us 10.

To reach N, we go right twice, giving us 11.

We have now constructed a variable-length encoding in which the most frequent letter, A, receives the shortest code.

That is the essential mechanism behind Huffman coding.

4. How Does the Computer Decode the Bits?

Here is the next challenge.

If we store the encoded word as:

100110110

How does the computer know where one letter’s code ends and the next begins?

It needs a way to distinguish the codes without inserting a separator after every letter.

Huffman coding solves this using a property called the prefix-free property.

A prefix-free code is one in which no complete symbol code is the beginning of another symbol’s code.

For our example:

  • A = 0
  • B = 10
  • N = 11

None of these codes is the prefix of another.

This means the decoder can read the bits from left to right and determine when it has reached a complete symbol.

Let’s decode the encoded word:

100110110

  1. Read 1. No complete code matches yet.
  2. Read 0. The sequence is 10, which represents B.
  3. Read the next 0. It represents A.
  4. Read 1, then 1. The sequence 11 represents N.
  5. Read 0. It represents A.
  6. Read 1, then 1. The sequence 11 represents N.
  7. Read the final 0. It represents A.

The result is:

BANANA

The original word has been reconstructed without losing a single letter.

In a real compressed file, the decoder also needs access to the coding information or equivalent metadata, such as a stored Huffman tree or code lengths. ZIP archives contain the information necessary to interpret their compressed data.

5. So Where Did the 600 MB Go?

Let’s return to our original question.

A 1 GB folder becomes a 400 MB ZIP archive. Where did the other 600 MB go?

The answer is that the compression algorithm found a more compact representation of the original data.

Digital files often contain patterns, repeated sequences, statistical regularities, or other forms of redundancy. Compression algorithms exploit these characteristics to reduce the number of bits needed for storage.

For example:

  • Text files may contain repeated words, characters, and patterns.
  • Spreadsheets may contain repeated values or predictable structures.
  • Logs may repeat timestamps, messages, and formatting.
  • Images may contain patterns that specialized image formats can represent efficiently.

Huffman coding can reduce the cost of representing frequently occurring symbols. Other compression techniques can identify repeated sequences or transform data into representations that are easier to compress.

ZIP compression commonly combines the DEFLATE algorithm, which uses LZ77-style sequence matching and Huffman coding.

In simplified terms, it can identify repeated sequences, represent them using references, and then encode the resulting symbols efficiently.

The important point is that the original information does not need to be discarded.

The compressed archive is smaller because the same information can sometimes be represented using fewer bits.

Does every 1 GB folder compress to 400 MB?

No.

The compression ratio depends on the contents of the folder.

A folder containing mostly plain text or repetitive data may shrink considerably. A folder containing JPEG images, MP4 videos, or files that have already been compressed may shrink very little.

For example, a 1 GB folder might become:

  • 400 MB if its contents compress well.
  • 900 MB if its contents compress only slightly.
  • Nearly 1 GB if its contents are already compressed or contain little exploitable redundancy.

Compression software cannot guarantee that every input will become smaller.

In fact, for some inputs, compression can produce a slightly larger file because the archive must also store metadata and other information.

6. Lossless vs. Lossy Compression

There is one more distinction worth understanding.

Not all compression works the same way.

Lossless compression allows the original data to be reconstructed exactly.

ZIP archives use lossless compression. When you extract an ordinary file from a ZIP archive, its original contents can be recovered bit for bit.

Other examples of lossless formats and methods include PNG image compression, FLAC audio compression, and gzip.

Lossy compression, on the other hand, reduces file size by discarding some information that may be less noticeable or less important for the intended use.

JPEG images and many common video and audio compression formats use lossy techniques.

This is why compressing a folder into a ZIP archive is different from converting a high-quality video into a lower-bitrate video. The latter may reduce quality, while ZIP compression is designed to preserve the original files exactly.

7. The Deeper Lesson: Compression Is About Redundancy

The most important idea to take away from Huffman coding is that data can often be represented more efficiently when we understand its structure.

Imagine writing a 500-page book in which the word “the” appears thousands of times. Instead of storing every occurrence in exactly the same way, a compression algorithm can exploit recurring patterns to save space.

Huffman coding applies this principle to symbol frequencies. Other algorithms exploit repeated sequences, predictable values, and mathematical relationships.

Together, these techniques form the foundation of modern data compression.

This is also why compression is an important topic in software engineering, networking, databases, cloud storage, multimedia systems, and distributed computing. Smaller representations can reduce storage requirements and the amount of data that must be transferred across a network.

However, compression requires computation, and the benefits depend on the data. A smaller archive may take less time to transfer, but compressing and extracting it also require processing time.

The goal is to find a useful balance between storage efficiency, processing cost, and speed.

Final Thoughts

The next time you create a ZIP file, remember that the computer isn’t necessarily throwing away information.

It’s looking for a smarter way to represent it.

Huffman coding demonstrates how frequently occurring symbols can receive shorter codes. ZIP compression builds on this broader idea by combining techniques that exploit patterns and redundancy in data.

So, where did those 600 MB go?

They were never necessarily missing. The original information was represented more compactly, allowing the computer to reconstruct the files when you unzip the archive.

That is the power of lossless data compression: less space, the same information.

If you found this explanation useful, follow along for more practical breakdowns of the computer science concepts behind the technology we use every day.

For more software engineering, IT, AI, cybersecurity, and infrastructure insights, visit my portfolio: https://abkarikari23.github.io/

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox, every week.

We don’t spam! Read our privacy policy for more info.


Join the conversation

Leave a comment

Your email address will not be published. Comments are reviewed before they appear.