# 38.1 Introduction to Compression



As an introduction to compression, consider the processes of creating and unzipping a zip file.

<pre class="language-bash"><code class="lang-bash">$ zip mobydick.zip mobydick.txt 
adding: mobydick.txt (deflated 59%)

$ ls -l
<strong>-rw-rw-r-- 1 jug jug 643207 Apr 24 10:55 mobydick.txt
</strong>-rw-rw-r-- 1 jug jug 261375 Apr 24 10:55 mobydick.zip
</code></pre>

Note that before and after unzipping, the file size changes!

## Compression Model 1: Algorithms on Bits

In our first model of compression, we consider compression as applying a _compression algorithm_ on a sequence of bits. To reverse the compression, we apply the inverse _decompression algorithm._

<figure><img src="https://2316889115-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCLYj7ccqvV6l4Pt9R0w5%2Fuploads%2FFG0MFuVNVZ3wL3buC33v%2Fimage.png?alt=media&#x26;token=4a5cc8eb-2d02-40e9-ad2f-32f039943edd" alt=""><figcaption><p>Compression and decompression.</p></figcaption></figure>

Say you had a text file called `example.txt`. If you were to zip that text file, you'd get `example.zip`, a zip file with a size much lesser than the original `example.txt` file. This is the main idea behind compression--a technique used to reduce file size.

Then, if you were to unzip `example.zip` into a file called `unzippedexample.txt`, you would notice no difference between `example.txt` and `unzippedexample.txt.` This is an indicator of **lossless** compression, where no information is lost.
