How Does Gif Compression Work

How Does GIF Compression Work?

How GIF Compression Works

When you start talking about image compression, you usually need a strong cup of Joe and a bullhorn to stay awake. My goal here is to relate the process of GIF compression in a way that makes sense, no caffeine required. You’re welcome.

We all know that images are made of pixels, and pixels are nothing more than tiny squares of color that make up an image. Let’s look at this example of a simple GIF image.

An Example

If we assign values to the pixels where: Blue = x Red = y Green = z, now we can describe this image row by row. The first row is all blue, so five x’s would represent the five blue pixels in the first row. The following rows are a little more complicated:

1: x-x-x-x-x

2: x-y-y-z-z

3: y-z-y-z-y

4: z-z-z-y-z

5: x-x-x-x-x

When a GIF is compressed, the description could look more like this:

1: 5x

2: x-2y-2z

3: y-z-y-z-y

4: 3z-y-z

5: 5x

As you can see, longer stretches of a solid color make the file more compressible (lines 1 and 5 are the most compressed) and speckled images cannot compress (line 3 is not compressed at all). When the color changes with each pixel in a row, there is no shorter way to convey the information.


Our 5×5 GIF does not seem too complex, but you can see how it reduces the character count and, therefore, the amount of data needed to describe the image. This results, obviously, in a smaller file size for the same information.

READ  What Is The Best Drawing Tablet