GIF

Also known as: Graphics Interchange Format

On this page 7

GIF, the Graphics Interchange Format, is a bitmap image format limited to 256 colors per frame that stores pixels as indices into a color palette and compresses them losslessly with the LZW algorithm. In photography and image processing, GIF matters mainly as an export target for short animations, simple web graphics and legacy compatibility, rather than as a format for photographic quality.

CompuServe introduced GIF in 1987, and the revised GIF89a specification of 1989 added transparency, animation timing and metadata extensions that keep the format alive today. Its universal support is its greatest strength, but its 8-bit palette and inefficient compression make it a poor container for continuous-tone photographs compared with JPEG, PNG, WebP or AVIF.

How GIF stores and compresses an image

A GIF file stores an image as indexed color: each pixel holds a number from 0 to 255 that points to an entry in a color table of up to 256 RGB values. A global color table applies to the whole file, and each frame may carry its own local color table, which is how animations can use different palettes from frame to frame.

The pixel indices are compressed with Lempel-Ziv-Welch coding, a dictionary method that replaces repeated sequences with shorter codes. LZW is lossless, so the indices decode exactly, but the conversion from a full-color photograph to 256 colors is itself a lossy step that happens before compression.

The table below lists the structural features defined by the GIF89a specification.

PropertyValue or behaviorPractical consequence
Color depth1 to 8 bits per pixelMaximum of 256 colors per frame
CompressionLZW, losslessEfficient for flat areas, weak for photos
TransparencyOne palette index fully transparentNo partial transparency, hard edges
AnimationMultiple frames with delaysTiming in hundredths of a second
InterlacingFour-pass row orderingCoarse preview while loading
MetadataComment and application extensionsNo standard EXIF or color profile support
Key technical properties of GIF

Why photographs lose quality as GIF

Photographs contain thousands to millions of distinct colors, so converting them to GIF requires color quantization, the process of choosing a 256-color palette and mapping every pixel to its nearest entry. Algorithms such as median cut and octree quantization pick the palette, but smooth gradients in skies and skin still break into visible steps known as posterization or banding.

To hide banding, encoders apply dithering, which scatters pixels of neighboring palette colors to simulate intermediate tones. Dithering improves perceived smoothness but introduces grain-like patterns and defeats LZW compression, because random-looking noise contains few repeated sequences. The result is a larger file of lower quality than an equivalent JPEG.

The table summarizes the main quantization and dithering choices and their trade-offs.

OptionEffect on qualityEffect on file size
Adaptive paletteBest match for the image colorsNeutral
Web-safe palettePoor, only 216 fixed colorsNeutral, obsolete today
No ditheringVisible banding in gradientsSmallest
Diffusion ditheringSmooth gradients, visible grainLargest
Pattern ditheringRegular texture, less noisyModerate
Palette and dithering choices for GIF export

GIF compared with other image formats

GIF is technically the weakest modern option for photographic content, but it remains the most widely supported format for animation in email clients, messaging tools and older software. Its neighbors in image processing each solve one of its limitations.

FormatColor depthCompressionAnimationBest use
GIF8-bit indexedLossless LZWYesSimple animations, universal compatibility
JPEG8-bit per channelLossyNoPhotographs on the web and in print
PNGUp to 16-bit per channelLosslessOnly as APNGGraphics, screenshots, alpha transparency
WebP8-bit per channelLossy or losslessYesSmaller web images and animations
AVIFUp to 12-bit per channelLossy or losslessYesHigh-efficiency images with HDR support
GIF and common alternatives

For the same animated clip, animated WebP or AVIF files are often several times smaller than a GIF, and a muted MP4 video loop can be smaller still. Many platforms that label content as GIF actually serve video files behind the scenes for that reason.

Creating efficient GIF animations

An efficient GIF depends on limiting dimensions, frame count and color variety, because file size grows roughly with pixel area multiplied by the number of frames. Photographers who turn burst sequences or cinemagraphs into GIF should plan these constraints before export rather than after.

SituationRecommended settingReason
Social preview or emailWidth of 480 to 640 pixelsKeeps files near a few megabytes
Cinemagraph with a static backgroundFrame optimization with transparencyStores only changed pixels
Smooth motion10 to 15 frames per secondBalances fluency and size
Gradient-heavy sceneReduce colors to 64 to 128 with light ditheringLimits banding without heavy noise
Modern websiteUse WebP, AVIF or MP4 insteadMuch smaller at better quality
Decisions for a practical GIF export

Limitations and common misconceptions about GIF

GIF is frequently misunderstood as a lossless photo format or as a format that cannot carry more than 256 colors in any form. The reality is more nuanced, and knowing it helps avoid poor format choices in a processing workflow.

  • Lossless compression does not mean lossless conversion: quantizing a photograph to 256 colors discards information.
  • More than 256 colors is possible in theory by tiling frames with local palettes, but the technique is impractical.
  • No color management: GIF has no standard way to embed an ICC profile, so colors may shift between devices.
  • The LZW patent no longer applies: the patents expired by 2004, so licensing is no longer a concern.
  • GIF strips camera metadata: EXIF and geotagging data from the original photograph are not preserved.

A non-technical view

A GIF is a picture file that can only use a box of up to 256 crayons. For a logo or a cartoon, that is plenty. For a photograph of a sunset, it is not enough, so the computer has to pick the closest crayons and sprinkle them together to fake the missing shades.

GIFs became famous because they can hold short, looping animations that work almost everywhere. They are convenient but not efficient: newer formats show moving pictures more sharply in much smaller files.

A concrete example

A travel photographer creates a cinemagraph of a café terrace in which only the steam from a coffee cup moves. She shoots a short 4K clip on a tripod, masks everything except the steam in an editing application, and exports a two-second loop at 600 pixels wide, 12 frames per second and 128 colors.

The first export, with full diffusion dithering, weighs about 9 MB. After switching to light dithering and enabling frame optimization so unchanged background pixels are stored once, the file drops to about 2.5 MB with no visible banding. For her own website she also exports an animated WebP version of under 1 MB, while the GIF version is kept for email newsletters, where WebP support remains inconsistent.