GIF Crate

← Blog

What Is a GIF? How It Works, Why It Loops & When to Use One

GIF Crate

A GIF is a short, looping image file. Learn how the format works, why GIFs loop, when to use one, and when another format is a better fit.

A GIF is a short picture file that can move, and then play again from the first frame. The name is Graphics Interchange Format. CompuServe released it in 1987, and the files people still trade are almost always GIF89a, the 1989 revision. Open one and the first six bytes spell GIF89a. The motion is a stack of frames, and the repeat is a note in the file that sends the player back to the start. It is not a video container, and it is not a JPEG that moves.

The hourglass below is one of those files. The sand is not a video track. It is eight full pictures, played in order.

Sand falling through an hourglass on a slate desk, 560 by 240
fall.gif is 560 by 240. Eight frames, and each one waits 12 hundredths of a second. The Netscape loop count is 0, so the sand goes back to the top bulb and starts again.

Each frame in that file paints the whole hourglass again. The top bulb starts full. By the last frame the sand has moved into the bottom bulb, and a single grain sits in the neck for that frame only. The next time you see the top bulb full, the player has returned to frame 0 because the loop count said to.

Frames share a 256-color paintbox

A pixel in a GIF stores an index, not its own red, green, and blue. The index points at a palette of at most 256 colors. A file may publish a shorter list, down to two colors for a simple mark, but 256 is the top. Icons, large type, and stickers drawn with a few inks survive that limit and stay sharp. A photograph is full of neighboring shades the table cannot name separately, so a sky or a cheek breaks into bands.

fall.gif spends five neighboring indexes on the sand, in stripes three pixels tall. That is already a small table, and the stripes are the table showing through. The next file keeps the same hourglass and the same eight frames, then throws away every sand index except two.

The same hourglass reduced to eight colors, with the sand in hard stripes, 560 by 160
bands.gif is 560 by 160 and publishes eight colors, not 256. The sand alternates between two of those colors every six pixels. The glass, the brass neck, and the slate each take one index, so there is nothing left for a soft shade between them.

The wide, short frame makes the stripes easier to count. Nothing in the file stores a gradient. Where fall.gif could step through five sand colors, bands.gif has to reuse two, so the steps get taller. A photograph of the same glass would ask for hundreds of close shades in the highlight alone. Those shades would land on the same two sand indexes, or on whichever indexes were left after the glass and the desk took theirs.

A flat-color hourglass sticker on a square canvas, 240 by 240
flat.gif is 240 by 240. The bulbs are larger in the frame, the sand is one index, and the glass has no extra highlight color. A sticker drawn with a few inks stays sharp inside the same limit that broke the sand into stripes above.

Those frames play in order, and each one stores a wait in hundredths of a second. A wait of 10 holds for a tenth of a second. A wait of 50 holds for half a second. The picture moves because the waits elapse one after another. No part of the file stores speech or music. The pixels are compressed with LZW, which keeps a flat area of one palette color small and grows as soon as nearby pixels need different indexes.

A wait of 100 holds the middle frame

The wait is an integer. There is no half step inside the file. Browsers also treat a stored wait of 0 or 1 as about a tenth of a second, so a frame that should flash by does not. The hourglass that pauses uses 12 for the quick frames and 100 for the held one. Both numbers are at least 2.

The same hourglass, held on the fourth frame for one second, 400 by 240
wait.gif is 400 by 240, with the same eight pictures as the falling sand. Frames 1, 2, 3, 5, 6, 7, and 8 wait 12. Frame 4 waits 100, which is one second. The pause is that number in the frame, not a clock sitting beside the file.

The narrower canvas is the same drawing with the same frame order. Only the fourth wait changed. If that 100 were another 12, the sand would pass the middle at the same pace as fall.gif.

The hourglass with every frame waiting 2 hundredths of a second, 360 by 180
fast.gif is 360 by 180. All eight frames wait 2. That is the shortest wait this page uses, because a browser treats a stored 0 or 1 as about a tenth of a second.

One index can be clear

Transparency, on the GIFs that have it, is one index in that palette with a flag. GIF89a can mark a single color clear, so pixels that use it show whatever is behind the image. Every other index is opaque. There is no partial fade for hair, smoke, or a soft shadow. People fake those edges by mixing nearby colors, and a hard-edged sticker comes through more cleanly than a portrait cut off a photograph.

Hourglass with the area outside the glass stored as one transparent index, 280 by 320
clear.gif is 280 by 320. Index 0 is the transparent color, and it covers the area outside the wood and the glass. The bulbs, the sand, and the frame use other indexes, so they stay opaque. The checker you see in the hole is the page behind the image, not a second color stored in the file.

This one is taller than the others so the two bulbs have room to read as glass rather than as a wide mark. The file still has a single clear index. A soft shadow around the foot would need partial opacity, and this format has no place to put it.

Later frames can keep an earlier grain

A frame may paint the whole screen again, or it may leave some of the previous picture where the new frame does not draw. These two hourglasses both paint a full picture every time. The difference is what that picture still contains.

The same hourglass with earlier falling grains still drawn into the later frames, 560 by 240
pile.gif is also 560 by 240 and eight frames. Each later frame still draws the grains from the earlier frames, so the column in the bottom bulb grows. fall.gif draws only the grain for the frame it is on. Both files replace the whole picture; the grains that remain were put into the later pictures on purpose.

Watch the bottom bulb. fall.gif keeps a single grain moving down. pile.gif leaves the earlier grains where they were, and the column gets longer as the frame number goes up. That is the file's own pixels. It is not the browser adding a trail after the fact.

The brass neck and one falling grain, stored as a 200 by 140 GIF
neck.gif is 200 by 140. Those pixels were cut from the 560 by 240 drawing before the file was written, so the header's screen is 200 by 140. The brass is at the top of this file and the lower bulb fills the rest. It is not a CSS crop of fall.gif.

The repeat is a loop count of zero

Looping is a number written in the file, not a trick the player adds. GIFs that repeat carry a Netscape application extension, the block Netscape Navigator 2.0 defined so an animation could play more than once. The block is named NETSCAPE2.0, and a 16-bit count inside it says how many times to repeat. Zero means keep going. That zero is the usual value behind an infinite loop, which is why so many GIFs seem to run forever without anyone setting a timer. A positive count is a finite repeat. Plenty of editors write zero and hide the control. Leave the block out and playback ends on the last frame. The older GIF87a file, from 1987, has nowhere to store the block.

Hourglass sand falling with no Netscape loop block, 480 by 180
once.gif is 480 by 180. The eight frames and the 12-hundredth waits match the falling sand, and the file has no NETSCAPE2.0 block. It plays through and stops on the last frame, with the sand left in the bottom bulb.
The same hourglass with a Netscape loop count of 1, 480 by 180
twice.gif is the same 480 by 180 pictures. The Netscape block is present, and the 16-bit count is 1. Chrome plays that count as two passes, about two seconds, and then stops on the last frame.

fall.gif, higher up, is the same kind of sand with the count left at 0. That one does not stop. The two files here are the finite cases: no block, and a count of 1.

A single-frame hourglass with the top bulb still full, 240 by 180
still.gif is 240 by 180 and stores one frame. The top bulb stays full because there is no next picture. A GIF can be a still image. The motion in the other files is the extra frames.

Where a short loop still belongs

Short loops, stickers, and simple graphics are where a GIF still fits. A reaction in chat, a diagram of about two seconds, or a small interface motion that has to sit in a page as an image can live inside 256 colors, and many editors and documents will show the file without a video player. flat.gif is that case. The square frame, the single sand color, and the hard glass edge are the sort of drawing the table was built for.

A sunset, a face whose color matters, or a clip with someone talking belongs in another format. The palette flattens the sky, every extra second is another full frame, and a voice has no place to go. Video keeps the duration and the sound, while a still format keeps the photograph's color. A GIF made from that material is a smaller, flatter copy, and editing the copy will not restore the shades or the speech the format never stored. bands.gif is the small version of that failure: eight colors, and the sand can only stripe.

When you want to change the file

A GIF that is already the right kind of file can still be edited. You can resize a GIF when you need to change a GIF's dimensions, crop a GIF to drop a margin, or shrink a GIF's file size when the download is heavier than the loop. Separate still pictures can turn still frames into a GIF. Those pages run in the browser, and the file stays on your device.

A sideways GIF can rotate the frames until it stands upright. To fix a loop that feels rushed or sleepy, change how long each frame waits. Play the frames backward when the motion should return to the first frame. A flat color behind the drawing can clear one background color. That clear color is the same single palette index described above, not a feathered mask.

GIF Crate is the set of those tools, for a file that already fits. The fit still comes down to the palette, the frames, the one clear color, and a loop count that is usually zero.