Technology Explained

How Does File Compression Work?

Ben Stegner Updated 26-07-2019

File compression is a core part of how the web works. It allows us to transfer files that would otherwise take too much bandwidth and time. Whenever you access ZIP files or view JPEG images, you’re benefiting from file compression.


Thus, at some point you’ve probably asked a question: how does file compression work? Here’s a basic look at how compression works.

What Does Compression Mean?

Simply put, file compression (or data compression) is the act of reducing the size of a file while preserving the original data. Doing so allows the file to take up less space on a storage device, in addition to making it easier to transfer over the internet or otherwise.

It’s important to note that compression is not infinite. While compressing a file into a ZIP reduces its size, you can’t keep compressing the file to further reduce the size to nothing.

Generally, file compression is split into two main types: lossy and lossless. Let’s look at how both of these work in turn.

How File Compression Works: Lossy Compression

Lossy compression reduces file size by removing unnecessary bits of information. It’s most common in image, video, and audio formats, where a perfect representation of the source media isn’t necessary. Many common formats for these types of media use lossy compression; MP3 and JPEG are two popular examples.


An MP3 doesn’t contain all the audio information from the original recording—instead, it throws out some sounds that humans can’t hear. You wouldn’t notice them missing anyway, so removing that info results in a lower file size with basically no drawbacks.

Similarly, JPEGs remove non-vital parts of images. For instance, in a picture containing a blue sky, JPEG compression might change all the sky pixels to one or two shades of blue, instead of using dozens of different shades.

However, the more heavily you compress a file, the more noticeable the drop in quality becomes. You’ve probably experienced this with muddy MP3 files uploaded to YouTube. For example, compare this high-quality music track:

With this heavily compressed version of the same song:


Lossy compression is suitable when a file contains more information than you need for your purposes. For instance, let’s say you have a huge RAW image file. While you probably want to preserve that quality when printing the image onto a large banner, it’s pointless to upload the RAW file to Facebook.

The picture contains so much data that isn’t noticeable when viewed on social media sites. Compressing the image to a high-quality JPEG throws out some information, but the image looks almost the same to the naked eye. See our comparison of popular image formats JPEG, GIF, or PNG? Image Filetypes Explained and Tested Do you know the differences between JPEGs, GIFs, PNGs, and other image filetypes? Do you know when you should use one instead of the other? Fear not, MakeUseOf explains everything! Read More for a deeper look at this.

Lossy Compression in General Usage

As we’ve mentioned, lossy compression is great for most forms of media. Because of this, it’s vital for companies like Spotify and Netflix that constantly transmit massive amounts of information. Reducing the file size as much as possible, while still preserving quality, makes their operation more efficient. Can you imagine if every video YouTube was stored and transmitted in its original uncompressed format?

But lossy compression doesn’t work so well for files where all the information is crucial. For instance, using lossy compression on a text file or a spreadsheet would result in garbled output. You really can’t throw anything out without severely harming the final product.


When saving in a lossy format, you can often set the level of quality. For instance, many image editors have a slider to choose the quality of a JPEG from 0-100.

Save as Compressed JPEG in Low Quality

Saving at something like 90 or 80 percent reduces the file size quite a bit, with little difference to the eye. But saving in poor quality or repeatedly saving the same file in a lossy format will degrade it.

Below you can see an example of this (click to see the larger images). On the left is the original image downloaded from Pixabay as a JPEG. The middle image is the result of saving this as a JPEG at 50 percent quality. And the rightmost image shows the original image saved instead as a 10 percent quality JPEG.


At a quick glance, the middle image doesn’t look too bad. You can only notice the artifacts around the edges of the boxes if you zoom in. Of course, the rightmost image immediately looks terrible.

Before cropping for upload, the file sizes were 874KB, 310KB, and 100KB respectively.

How File Compression Works: Lossless Compression

Lossless compression is a way of reducing file size so that you can perfectly reconstruct the original file. Contrary to lossy compression, it doesn’t throw any information out. Instead, lossless compression essentially works by removing redundancy.

Let’s take a basic example to show what this means. Below is a stack of 10 bricks: two blue, five yellow, and three red. This stack is a simple way to illustrate those blocks, but there’s another way to do so.

How does file compression work? Lossless brick example

Instead of showing all 10 blocks, we can remove all but one of each color. Then, if we use numbers to show how many bricks of each color there were, we’ve represented the exact same bit of information using far fewer bricks. Instead of 10 bricks, we now only need three.

how file compression works: lossless compression bricks

This is a simple illustration of how lossless compression is possible. It stores the same information in a more efficient way by removing redundancy. Consider an actual file, where the below string:


Can “compress” to the following, much shorter form:


This allows us to use seven characters instead of 24 to represent the same data, which is a significant saving.

Lossless Compression in Everyday Use

Windows File Zipped Example

As we mentioned above, lossless compression is important in cases where you can’t remove any of the original file. If you’ve been curious as to how ZIP files work, this is the answer.

When you create a ZIP file from a program executable in Windows, it uses lossless compression. The ZIP file compression is a more efficient way to store the program, but when you unzip (decompress) it, all the original information is present. If you used lossy compression to compress executables, the unzipped version would be damaged and unusable.

Common lossless formats include PNG for images, FLAC for audio, and ZIP. Lossless formats for video are rare, because they would take up massive amounts of space.

When to Use Lossy vs. Lossless Compression

Export an MP3 in Audacity

Now that we’ve looked at both forms of file compression, you might wonder when you should use one or the other. As it turns out, there is no “better” form of compression—it all depends on what you’re using the files for.

In general, you should use lossless compression when you want a perfect copy of the source material, and lossy compression when an imperfect copy is good enough. Let’s look at another example to see how they can work in harmony.

Say that you’ve just dug up your old CD collection and want to digitize it How to Convert CDs, Cassettes, and MiniDiscs to MP3 If you have old CDs, cassette tapes, MiniDiscs, or vinyl records that you want to get rid of, it's time to digitize your collection. Here's everything you need to know. Read More so you have all your music on your computer. When you rip your CDs, it makes sense to use a format like FLAC, which is lossless. This lets you have a master copy on your computer that’s as good as the original CD.

Later, perhaps you want to put some music on your phone or an old MP3 player so you can listen on-the-go. You probably don’t care about your music being in perfect quality for this, so you can convert the FLAC files to MP3 How to Convert FLAC to MP3 for Free Do you need to convert FLAC audio files to MP3? Then here are the free apps you need to check out on Windows, Mac, Linux, and the web. Read More . This gives you an audio file that’s still perfectly listenable, but doesn’t take up as much space on your mobile device. The quality of the MP3 converted from the FLAC will be as good as if you’d created a compressed MP3 right from the original CD.

The type of data represented in a file can also dictate which type of compression is best. Because PNG images use lossless compression, they offer small file sizes for images with lots of uniform space, like computer screenshots. However, you’ll notice that PNGs take up much more space when they represent the jumble of colors in real-world photos.

Concerns During File Compression

As we’ve seen, converting lossless formats to lossy is fine, as is converting one lossless format to another. However, you should never convert a lossy format to lossless, and should beware converting one lossy format to another.

Converting lossy formats to lossless is simply a waste of space. Remember that lossy formats throw data out; it’s impossible to recover that data.

Say you have a 3MB MP3 file. Converting that to FLAC might result in a 30MB file, but those 30MB contain the exact sounds that the much smaller MP3 did. Converting back to a lossless format doesn’t “recover” the information that the MP3 compression threw out.

Finally, as mentioned earlier, converting one lossy format to another (or repeatedly saving in the same format) will degrade the quality further. Every time you apply the lossy compression, you lose more detail. This becomes more and more noticeable until the file is essentially ruined.

How Does Compression Work? Now You Know

We’ve taken a look at both lossy and lossless compression to see how they work. Now you know how it’s possible to store a file at a smaller size than its original form, and how to choose the best method for your needs.

Of course, the algorithms that decide what data gets thrown out in lossy methods and how to best store redundant data in lossless compression are much more complicated than we’ve explained here. There’s a lot more to discover on this topic if you’re interested.

Tried out lossless compression and need to send something to a friend? Try these fast ways to transfer large files online. And if you need help compressing large audio files How to Compress Large Audio Files: 5 Easy and Effective Ways Need to reduce the size of your audio files? Here are several ways to compress large audio files. Read More , here are some easy and effective ways.

Related topics: File Compression, ZIP Files.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. nicolas
    October 30, 2019 at 1:15 pm

    This was an amazing explanation, Thanks!

  2. The IT Guy
    July 31, 2019 at 5:13 am

    And what type of compression is Linux/Unix based system use? I downloaded a custom Wi-Fi dictionary a few years back and it was about 10, 15 gigs. After decompressing, it had a wooping 55 freaking gigs... How? I'd love to know how they did it and store my music and photos like that... I don't remember if it was a .tar file, or something else...

  3. Rob
    May 21, 2019 at 4:18 pm

    This is the best 5-minute explanation of file compression that I have found. Great job!

  4. mikael wester
    May 11, 2019 at 7:11 am

    Wonderful ! Even I understand the basic concept behind it.

  5. Yash Jain
    November 4, 2018 at 8:15 pm

    Please give size of given three image so as to compare. Anyway nicely explained.

  6. Roche
    July 26, 2018 at 2:30 am

    That was really informative. Thanks! :)

  7. TJ
    May 26, 2018 at 12:27 pm

    Great article, thanks!

    March 23, 2018 at 6:03 am

    Can you explain the mechanism involved in this process. I mean how the compression process takes..What will happen when a file is compressed..The change in bit position when compressed...etc.,

  9. Terrance
    March 21, 2018 at 3:53 am

    When using lossless compression, it will not decrease in size the more you try to compress. It will actually increase in size.

    -rwxrwxrwx 1 root root 120037581 Mar 20 21:50 grandma.more.1.tar.gz
    -rwxrwxrwx 1 root root 120018568 Mar 20 21:49 grandma.more.tar.gz
    -rwxrwxrwx 1 root root 120203267 Mar 20 21:11 grandma.tar.gz

    So, once it is compressed, that is as far as it will go.

    • Terrance
      March 21, 2018 at 3:57 am

      Just adding on that it only compressed just a slight bit on the second run, then it started to increase after that. So you will gain hardly anything by compressing more than one time, but will lose size if you keep compressing.

  10. Jr. Kennett Holiday-Long
    March 18, 2018 at 7:06 am

    I'm not gonna lie...

    I loved it.

  11. Thecrimson4ker
    December 14, 2017 at 10:59 pm

    Great Job... Thanks

  12. saman kayani
    October 2, 2017 at 3:40 am

    superb ..thanks

  13. saman kayani
    October 2, 2017 at 3:40 am

    superb ,.... thanks

  14. L
    July 2, 2017 at 12:58 am

    Very helpful, thanks!

  15. nat
    April 18, 2017 at 1:32 pm

    LOVED the Article

  16. Vineetha
    February 25, 2017 at 7:50 am


  17. 6Block
    February 3, 2017 at 1:45 pm

    There's 6 Yellow blocks not 5.

    • Zack milner
      April 28, 2017 at 1:40 pm

      Shut up

    • definitely6
      May 25, 2017 at 2:25 am

      good catch

    • Joshua
      July 19, 2017 at 10:25 pm

      Exactly my observation!

  18. Carol Farmer
    January 27, 2017 at 11:26 pm

    Ridiculous! No help at all! Just alot of blah blah blah!

    • hckkkker6969
      February 3, 2017 at 2:31 pm

      this is why nobody wants to be your friend carrot

      • ye xd
        June 1, 2017 at 3:48 am

        lol carrot nice

    • zeeshan nasir
      August 9, 2017 at 3:41 pm

      yes this is

  19. Adam
    January 12, 2017 at 10:32 pm

    Very nice explanation

  20. Adam
    January 12, 2017 at 10:31 pm

    Very nice way of explaining

  21. Martin Pereda
    August 27, 2016 at 5:57 pm

    que onda, no le entendi, auiida por favor

    • hello_world
      December 11, 2016 at 5:49 am


    • Joshua
      July 19, 2017 at 10:25 pm

      ivela bekitta ninge? yaargu sumne artha aagalla

  22. Di
    August 17, 2016 at 2:52 pm

    Thanks for the article! Loved it. Ehmm... one comment on loseless compression: two red, five yellow and three blue is LOSSY since it lost one yellow brick (There are 6!) tc! ;)

  23. Anonymous
    August 9, 2016 at 5:49 am

    I know some compression works like this:
    it will find common strings (example: 01001100 [Yes I know the compressors don't see it as binary just let me explain]) or what it finds to be common, and will change that into say a 7 or some unicode character or basically something that the software/compression software recognizes and when the file is being rebuilt will change that 7 back into the example string. So in theory using lossless compression methods that do this, could you keep compressing a file using those different methods, aka: file > > > > and etc (I don't know if those ones are lossless or not but I'm just making an example.) would the file get smaller every time? Of course it would, right? So basically I'm asking is that possible, one of the main reasons I had this question is because sometimes I download files that are .tar.gz so does that mean they compressed the .tar into a .gz? Or am I just stupid. (Hopefully not that one).

    -Sorry it's a long question, just something that's been bothering me.

    • C. Lupus
      August 9, 2016 at 10:12 pm

      What you're talking about doesn't put headers and metadata into the equation. Compression is basically a tradeoff so everytime you compress a file you are adding a certain amount of metadata to it.

      So depending on the size of that header, your compressed file could end up bigger than the original file if compressed too many times.

      It all depends on the algorithms used.

    • anon
      March 30, 2017 at 7:00 pm

      I have repeatedly compressed files with lossless methods and the file stops getting any smaller. That tells me I have reached the limit for that method (lossless). Another method might find more compression, but it is clearly less and less effective.

  24. Magicrafter13
    August 9, 2016 at 5:37 am

    I know some compression works like this:
    it will find common strings (example: 01001100 [Yes I know the compressors don't see it as binary just let me explain]) or what it finds to be common, and will change that into say a 7 or some unicode character or basically something that the software/compression software recognizes and when the file is being rebuilt will change that 7 back into the example string. So in theory using lossless compression methods that do this, could you keep compressing a file using those different methods, aka: file > > > > and etc (I don't know if those ones are lossless or not but I'm just making an example.) would the file get smaller every time? Of course it would, right? So basically I'm asking is that possible, one of the main reasons I had this question is because sometimes I download files that are .tar.gz so does that mean they compressed the .tar into a .gz? Or am I just stupid. (Hopefully not that one).

    -Sorry it's a long question, just something that's been bothering me.

    • Joshua
      July 19, 2017 at 10:35 pm

      I am glad it's bothering you :)

  25. Magicrafter13
    August 9, 2016 at 5:30 am

    This isn't really a question about the article but I know this much some (maybe all but I think just most) compression methods involve finding common strings, what I mean is if a certain block of code is really common, anyway they find those and replace them with a smaller block, possibily even one character that the compression software recognizes so that when it is reconstructed it replaces that block/single character with whatever it's representing. I know that explanation might not make sense so tell me if it doesn't, but anyway my question is, theoretically if you compressed a file with say .zip, then compressed the .zip into a .rar, then compressed that into a .7z and so on into other different formats that use the method I just mentioned above would each compression help make the file smaller (and we are only talking about Lossless compressors because obviously lossy would be smaller since you said it yourself, it loses data.)

    -Sorry for this long question, it's just something that's been on my mind. the main reason is sometimes I download files that are like .tar.gz or something so I assume the .tar was compressed using .gz

    • tomysshadow
      October 23, 2016 at 4:06 am

      Actually, tar files don't offer any compression. The gz does all the work of compressing it. Tar just contains the gz as is with no compression.

    • Joshua
      July 19, 2017 at 10:35 pm

      I am glad you apologized for the long question :)

  26. L Brock
    August 1, 2016 at 1:16 am

    Good simple explanation.

  27. Ashwath
    July 24, 2016 at 10:44 pm

    Beautifully Written! Loved the way you described it!

  28. Arun
    July 7, 2016 at 9:27 am

    Very Simple.Awesome......

  29. pearl
    July 5, 2016 at 12:12 pm

    Very clear, helpful and interesting. Thanks a lot

    • superjim1000JimjIM
      July 28, 2016 at 2:41 am

      You stop that

      • Bebazled_chipmonkey
        July 28, 2016 at 2:54 am

        Ding dong, phr33 b8 plox

        wow! how could I ever eat all this b8!

        Also R8 me thread

        • Joshua
          July 19, 2017 at 10:34 pm

          I am glad you ate all this :)

      • Joshua
        July 19, 2017 at 10:34 pm

        I am glad you asked him to stop :)

  30. puppy0cam
    June 3, 2016 at 4:19 am

    what about using division to make the character amount go down by getting the data into the zeroes and ones and then you use division on it to bring it to a smaller value.

  31. Jason
    June 1, 2016 at 8:19 pm

    Great examples, I was always curious how ZIP files could compress so much data.

  32. Mohammad Sharaf Ali
    May 21, 2016 at 12:26 pm

    Straight and to the point. Really enjoyed while reading the article.

    • Joshua
      July 19, 2017 at 10:34 pm

      I am glad you enjoyed :)

  33. Stuart
    April 7, 2016 at 11:02 pm

    Simple but brilliant. You've made the complicated sound simple. Not an easy thing to do! Well done.

  34. Anthony
    March 17, 2016 at 8:11 pm

    An excellent explanation. Thanks!

    • Justin Pot
      March 22, 2016 at 2:07 pm

      I'm glad it was useful!

  35. ankit sarode
    February 6, 2016 at 5:01 pm

    nice explanation :)

    • Justin Pot
      February 6, 2016 at 5:14 pm

      I'm glad it was useful for you!

  36. Anonymous
    February 2, 2016 at 9:34 pm

    thanks man. great explanation.

  37. Steve Yeldon
    January 25, 2016 at 3:14 pm

    There are 6 yellow bricks.

    • Justin Pot
      January 25, 2016 at 3:26 pm

      Compression errors happen.

      • James
        March 9, 2016 at 11:23 am

        "I see what you did there."

      • Varun
        April 8, 2016 at 8:11 pm

        well said lol

    • Anonymous
      February 2, 2016 at 9:35 pm


      • Joshua
        July 19, 2017 at 10:33 pm

        I am glad you found it to be truthful :)

  38. Mary
    January 10, 2016 at 6:58 pm

    Thank you for the simplicity (compression?) in this information. I am using it for an entirely different application!

    • foobar
      March 26, 2016 at 11:56 pm

      Funny stuff m8

      • Joshua
        July 19, 2017 at 10:28 pm

        I am glad you find it funny

  39. Nachos ho
    December 6, 2015 at 8:52 am

    I have to say,thanks, humour is the line. Needing to cross it is apparent from what I read but i cannot add two more than enough of the same thing blah blah. F7U12 beast

    • Justin Pot
      December 6, 2015 at 4:24 pm

      Umm...thanks? I think? I'm not sure what you're trying to say but I'm glad you stopped by.

      • aneesh joshi
        March 6, 2016 at 1:43 pm

        i think he used lossy compression on that...

        • Joshua
          July 19, 2017 at 10:28 pm

          I am glad you thought I used lossy compression :)

  40. Pooya
    November 16, 2015 at 10:11 pm

    awesome explanation,
    please correct this part :
    Of course, repeatedly compressing a file using lossless methods decreases the quality.
    its about lossy compressing not lossless.

    • Justin Pot
      November 16, 2015 at 11:22 pm

      Three years later with a great correction, thanks so much!

  41. Anonymous
    August 31, 2015 at 10:02 am

    Wonderful explanation.
    Before doing Compression on my site i used to upload compressed images that i used to compress from Now i have used Gzip Compression script that does compression on runtime. How that works, here i found my answer. It is really awesome.
    Good Job.

    • Joshua
      July 19, 2017 at 10:29 pm

      I am glad you found it awesome :)

  42. Anonymous
    July 20, 2015 at 6:26 pm

    Awesome explanation bro. Thank you. :)

  43. Haider-Bakhsh Janyaro
    November 20, 2012 at 4:19 am

    Simplest definition i have ever seen.
    Thanks bro

  44. Douglas Mutay
    October 31, 2012 at 11:07 am

    Clear as water. Thanks for illustration that make things more simple to understand.

  45. Lisa Santika Onggrid
    October 14, 2012 at 11:28 am

    Clear explanation. Now I understand how those softwares give our files 'magic slimming pills'.

    Now is there any cloud storage that enable us to upload compressed folder, then choose just one file from that folder to download?

    • Justin Pot
      October 14, 2012 at 1:48 pm

      If it exists I don't know about it. I'll come back here if I find anything.

    • puppy0cam
      June 3, 2016 at 4:22 am

      doing that would mean uncompressing the entire thing, so what your asking is to upload a compressed file and then the cloud decompresses it and then stores the contents.

  46. Kaashif Haja
    October 14, 2012 at 2:31 am

    Good Examples!

  47. Doc
    October 13, 2012 at 9:08 pm

    "Another example of lossless compression is the JPEG image." LOSSY.

  48. Sam Kar
    October 13, 2012 at 12:58 pm

    Nice explanation Justin, I enjoyed reading. Thanks

    I use WinRar- any idea what is the default compression offered (lossy/loss-less)?

    • Justin Pot
      October 13, 2012 at 1:50 pm

      Winrar and software like it is completely lossless. It's why the file is exactly the same as before once you extract it.

      • Grr
        October 13, 2012 at 2:56 pm

        Thanks Justin.

  49. Jacob Mathew
    October 13, 2012 at 6:01 am

    I did not understand this in college.But now I do.

    • Joshua
      July 19, 2017 at 10:29 pm

      I am glad you do :)

  50. Alex Perkins
    October 12, 2012 at 5:47 pm

    Thank you! Finally a simple explanation, I like how you showed it with the LEGO.

  51. Igor Rizvi?
    October 12, 2012 at 1:30 pm

    I thought i knew this,but now i see i was wrong...thanks

    • Joshua
      July 19, 2017 at 10:32 pm

      I am glad you're wrong :)

  52. wickedbros
    October 12, 2012 at 1:16 pm

    there are six yellow bricks :))

    • Joshua
      July 19, 2017 at 10:30 pm

      I am glad you found it :)

  53. Harish Jonnalagadda
    October 12, 2012 at 12:15 pm

    Had to learn this in college! Thanks for the article.

  54. Raj Sarkar
    October 12, 2012 at 9:39 am

    Thanks for this! :D

  55. Craig Friday
    October 12, 2012 at 5:13 am

    Good explanation but the missing data in mp3s is vary notable if you know what to listen for

    • Justin Pot
      October 13, 2012 at 1:51 pm

      Depends how much you compress it, but yes: you can hear it. You can see the compression in images and videos too, if you know what you're looking for, but many decided the trade off is worth it.

  56. Eric Wilborn
    October 12, 2012 at 2:54 am

    Nice explanation. I'll refer people to it instead of doing the work myself next time ;)

    • Joshua
      July 19, 2017 at 10:30 pm

      I am glad you'll refer to this :)

      • Hugo
        February 26, 2018 at 6:45 pm

        I'm glad you're glad :)

  57. Manuel Guillermo López Buenfil
    October 11, 2012 at 11:59 pm

    That was a quite nice explanation. I did know that jpg files were compressed, but I thought that png files weren't, due to their bigger size. This actually creates a very nice comparison between lossy and lossless compression: a file usually becomes 5 times smaller when converted from png to jpg!

  58. Mike Merritt
    October 11, 2012 at 8:45 pm

    Is a jpeg photo "lossy" or "lossless" ?? You say: "Another example of lossless compression is the JPEG image." but you have it under the "lossy" header.

    • Joel Lee
      October 11, 2012 at 9:00 pm

      I believe it's a typo. JPEG is lossy.

    • Florin Ardelian
      October 11, 2012 at 9:12 pm

      JPEG is loosy (lower quality), PNG is loosles (maintains quality).

    • Justin Pot
      October 13, 2012 at 1:52 pm

      Oops! That's a typo.

      • Mike Merritt
        October 15, 2012 at 9:00 pm

        So - are you going to fix the typo in the article - or just leave it there to confuse future generations ???

        • Justin Pot
          October 16, 2012 at 6:16 pm

          Funny story: I don't actually have the ability to edit articles. I've made the editors aware, so it should be fixed soon.

        • Mike Merritt
          October 19, 2012 at 3:32 pm

          Thanks - Done.

    • Joshua
      July 19, 2017 at 10:31 pm

      I am glad you found it :)

  59. Roman Vávra
    October 11, 2012 at 8:23 pm

    Nice explanation :)