If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

The need for compression

Modern computers can store increasingly large numbers of files, but file size still matters. The smaller our files are, the more files we can store.
We use compression algorithms to reduce the amount of space needed to represent a file.
There are two types of compression: lossless and lossy.
Lossless compression algorithms reduce the size of files without losing any information in the file, which means that we can reconstruct the original data from the compressed file.
Lossy compression algorithms reduce the size of files by discarding the less important information in a file, which can significantly reduce file size but also affect file quality.
We'll first explore lossless compression techniques that work for text documents, simple images, and all binary data, and then explore lossy compression techniques for photos and audio.

Want to join the conversation?

  • blobby green style avatar for user Lorenzo4soccer
    In lossy compression what do you mean by discarding less important information? In an .JPEG or any image related file extension i could understand that those files when they're reduced they lose quality, but what about like documents?
    (7 votes)
    Default Khan Academy avatar avatar for user
    • male robot donald style avatar for user Steven Lwanda
      Lossy compression involves removing less important information and so this allows compression of files like audios, pictures or videos since the lost information might be unnoticeable but for documents, lossy compression cannot be used since it can lead to missing of some characters hence making the document unreadable so for documents only lossless compression works
      (43 votes)
  • blobby green style avatar for user aben2027
    How on earth is this so confusing, yet understandable? To me its kinda a teeter-toter of I understand this, to I have no clue....
    (16 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user nicolascor2079
    what is your favorite candy?
    (8 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user 21jmclean
    This is very interesting 🤔🤔💭
    (8 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user chansovanmonyyoeun03
    How can we reconstruct the original data? Why don't people just use lossless compression?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • starky ultimate style avatar for user KLaudano
      Losslessly compressed files usually contain some sort of table that allows the original file to be reconstructed.

      You usually won't notice the loss of quality in images and videos caused by lossy compression and lossy compression tends to give better compression ratios than lossless compression.
      (8 votes)
  • blobby green style avatar for user Ashwika Ganti
    how do you make information smaller and compress it even though theres a lot in lossless? how can it be made smaller with the same amount of info
    (2 votes)
    Default Khan Academy avatar avatar for user
    • starky ultimate style avatar for user KLaudano
      Lossless compression describes data in a different way that takes up less memory. For example, instead of explicitly stating the series of numbers "1, 4, 9, 16, 25, 36, 49, 64, 81, 100", we could say "x^2 for 0 < x < 11". The two descriptions are equivalent, but the second is smaller.
      (8 votes)
  • blobby green style avatar for user ericksenza
    what is the piont of this
    (3 votes)
    Default Khan Academy avatar avatar for user
    • scuttlebug yellow style avatar for user pufferfish56
      Compression is useful if you want to store more things with the same amount of space, or if you want to transmit data faster. Lossless compression removes redundant information, you can reconstruct the original file from a lossless compression. Lossy compression removes information that can't be reconstructed, but it can compress a file more than lossless compression can, and sometimes the lost information wasn't that important, like particular pixels that look slightly different in a picture.
      (3 votes)
  • blobby green style avatar for user leonardo.wiest
    Zǎo shang hǎo zhōng guó!
    Xiàn zài wǒ yǒu bing chilling
    Wǒ hěn xǐ huān bing chilling
    Dàn shì "sù dù yǔ jī qíng jiǔ" bǐ bing chilling
    "sù dù yǔ jī qíng, sù dù yǔ jī qíng jiǔ"
    Wǒ zuì xǐ huān
    Suǒ yǐ xiàn zài shì yīn yuè shí jiān
    Zhǔn bèi
    Yī, èr, sān
    Liǎng gè lǐ bài yǐ hòu
    "Sù dù yǔ jī qíng jiǔ"
    Liǎng gè lǐ bài yǐ hòu
    "Sù dù yǔ jī qíng jiǔ"
    Liǎng gè lǐ bài yǐ hòu
    "Sù dù yǔ jī qíng jiǔ
    Bù yào wàng jì, bù yào cuò guò
    Jì dé qù diàn yǐng yuàn kàn "sù dù yǔ jī qíng jiǔ"
    Yīn wéi fēi cháng hǎo diàn yǐng
    Dòng zuò fēi cháng hǎo
    Chà bù duō yī yàng bing chilling
    Zài jiàn
    (4 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user hinesj10690
    Lossy compression involves removing less important information and so this allows compression of files like audios, pictures or videos since the lost information might be unnoticeable but for documents, lossy compression cannot be used since it can lead to missing of some characters hence making the document unreadable so for documents only lossless compression works
    (3 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user jeff li
    do we have any videos for this? Reading on computer hinders my comprehending quality lol
    (3 votes)
    Default Khan Academy avatar avatar for user