The format supports up to 8 bits per pixel for each image, allowing a single image to reference its own palette of up to different colors chosen from the bit RGB color space. It also supports animations and allows a separate palette of up to colors for each frame. These palette limitations make GIF less suitable for reproducing color photographs and other images with color gradients, but it is well-suited for simpler images such as graphics or logos with solid areas of color. Unlike video, the GIF file format does not support audio.
GIF images are compressed using the Lempel—Ziv—Welch LZW lossless data compression technique to reduce the file size without degrading the visual quality. This compression technique was patented in Controversy over the licensing agreement between the software patent holder, Unisys , and CompuServe in spurred the development of the Portable Network Graphics PNG standard.
By all the relevant patents had expired. CompuServe introduced GIF on June 15, to provide a color image format for their file downloading areas, replacing their earlier run-length encoding RLE format, which was black and white only. GIF became popular because it used LZW data compression , which was more efficient than the run-length encoding that formats such as those used by PCX and MacPaint , and fairly large images could therefore be downloaded in a reasonably short time, even with very slow modems.
The original version of GIF was called 87a. The 89a specification also supports incorporating text labels as text not embedding them in the graphical data , but as there is little control over display fonts, this feature is not widely used. CompuServe encouraged the adoption of GIF by providing downloadable conversion utilities for many computers. In September Netscape Navigator 2. The feature of storing multiple images in one file, accompanied by control data, is used extensively on the Web to produce simple animations.
The optional interlacing feature, which stores image scan lines out of order in such a fashion that even a partially downloaded image was somewhat recognizable, also helped GIF's popularity,  as a user could abort the download if it was not what was required.
As a noun , the word GIF is found in the newer editions of many dictionaries. The press's lexicographers voted it their word of the year , saying that GIFs have evolved into "a tool with serious applications including research and journalism". Steve Wilhite says that the intended pronunciation deliberately echoes the American peanut butter brand Jif , and CompuServe employees would often say "Choosy developers choose GIF", spoofing this brand's television commercials. The American Heritage Dictionary  cites both, indicating "jif" as the primary pronunciation, while Cambridge Dictionary of American English  offers only the hard-"G" pronunciation.
The disagreement over the pronunciation led to heated Internet debate. On the occasion of receiving a lifetime achievement award at the Webby Award ceremony, Wilhite rejected the hard-"G" pronunciation,    and his speech led to 17, posts on Twitter and 50 news articles.
In February , The J. Smucker Company , the owners of the Jif peanut butter brand, partnered with animated image database and search engine Giphy to release a limited-edition "Jif vs. Conceptually, a GIF file describes a fixed-sized graphical area the "logical screen" populated with zero or more "images". Many GIF files have a single image that fills the entire logical screen.
Others divide the logical screen into separate sub-images. The images may also function as animation frames in an animated GIF file, but again these need not fill the entire logical screen. GIF files start with a fixed-length header "GIF87a" or "GIF89a" giving the version, followed by a fixed-length Logical Screen Descriptor giving the pixel dimensions and other characteristics of the logical screen.
The screen descriptor may also specify the presence and size of a Global Color Table, which follows next if present. An image starts with a fixed-length Image Descriptor, which may specify the presence and size of a Local Color Table which follows next if present.
The image data follows: one byte giving the bit width of the unencoded symbols which must be at least 2 bits wide, even for bi-color images , followed by a linked list of sub-blocks containing the LZW-encoded data. Extension blocks blocks that "extend" the 87a definition via a mechanism already defined in the 87a spec consist of the sentinel, an additional byte specifying the type of extension, and a linked list of sub-blocks with the extension data. Extension blocks that modify an image like the Graphic Control Extension that specifies the optional animation delay time and optional transparent background color must immediately precede the segment with the image they refer to.
The linked lists used by the image data and the extension blocks consist of series of sub-blocks, each sub-block beginning with a byte giving the number of subsequent data bytes in the sub-block 1 to The series of sub-blocks is terminated by an empty sub-block a 0 byte. This structure allows the file to be parsed even if not all parts are understood.
A GIF marked 87a may contain extension blocks; the intent is that a decoder can read and display the file without the features covered in extensions it does not understand. The full detail of the file format is covered in the GIF specification. GIF is palette-based: the colors used in an image a frame in the file have their RGB values defined in a palette table that can hold up to entries, and the data for the image refer to the colors by their indices 0— in the palette table.
The color definitions in the palette can be drawn from a color space of millions of shades 2 24 shades, 8 bits for each primary , but the maximum number of colors a frame can use is This limitation seemed reasonable when GIF was developed because few people could afford the hardware to display more colors simultaneously. Simple graphics, line drawings, cartoons, and grey-scale photographs typically need fewer than colors.
Each frame can designate one index as a "transparent background color": any pixel assigned this index takes on the color of the pixel in the same position from the background, which may have been determined by a previous frame of animation.
Many techniques, collectively called dithering , have been developed to approximate a wider range of colors with a small color palette by using pixels of two or more colors to approximate in-between colors. These techniques sacrifice spatial resolution to approximate deeper color resolution. This is often not an ideal solution for GIF images, both because the loss of spatial resolution typically makes an image look fuzzy on the screen, and because the dithering patterns often interfere with the compressibility of the image data, working against GIF's main purpose.
In the early days of graphical web browsers [ when? When bit color became the norm palettes could instead be populated with the optimum colors for individual images. A small color table may suffice for small images, and keeping the color table small allows the file to be downloaded faster. Both the 87a and 89a specifications allow color tables of 2 n colors for any n from 1 through 8.
Most graphics applications will read and display GIF images with any of these table sizes; but some do not support all sizes when creating images. Tables of 2, 16, and colors are widely supported. Although GIF is almost never used for true color images, it is possible to do so. Alternatively, the GIF89a specification introduced the idea of a "transparent" color where each image block can include its own palette of visible colors plus one transparent color.
A complete image can be created by layering image blocks with the visible portion of each layer showing through the transparent portions of the layers above. To render a full-color image as a GIF, the original image must be broken down into smaller regions having no more than or different colors.
Each of these regions is then stored as a separate image block with its own local palette and when the image blocks are displayed together either by tiling or by layering partially transparent image blocks the complete, full-color image appears. For example, breaking an image into tiles of 16 by 16 pixels pixels in total ensures that no tile has more than the local palette limit of colors, although larger tiles may be used and similar colors merged resulting in some loss of color information.
Since each image block requires its own local color table, a GIF file having lots of image blocks can be very large, limiting the usefulness of full-color GIFs.
Many rendering programs interpret tiles or layers as animation frames and display them in sequence as an endless animation  with most web browsers automatically displaying the frames with a delay time of 0. Microsoft Paint saves a small black-and-white image as the following GIF file. Paint does not make optimal use of GIF; due to the unnecessarily large color table storing a full colors instead of the used 2 and symbol width, this GIF file is not an efficient representation of the pixel image illustrated enlarged above.
Although the Graphics Control Extension block declares color index 16 hexadecimal 10 to be transparent, that index is not used in the image. The only color indexes appearing in the image data are decimal 40 and , which the Global Color Table maps to black and white, respectively. Note that the hex numbers in the following tables are in little-endian byte order, as the format specification prescribes. The image pixel data, scanned horizontally from top left, are converted by LZW encoding to codes that are then mapped into bytes for storing in the file.
The pixel codes typically don't match the 8-bit size of the bytes, so the codes are packed into bytes by a "little-Endian" scheme: the least significant bit of the first code is stored in the least significant bit of the first byte, higher order bits of the code into higher order bits of the byte, spilling over into the low order bits of the next byte as necessary.
Each subsequent code is stored starting at the least significant bit not already used. This byte stream is stored in the file as a series of "sub-blocks". Each sub-block has a maximum length bytes and is prefixed with a byte indicating the number of data bytes in the sub-block. The series of sub-blocks is terminated by an empty sub-block a single 0 byte, indicating a sub-block with 0 data bytes. A slight compression is evident: pixel colors defined initially by 15 bytes are exactly represented by 12 code bytes including control codes.
The encoding process that produces the 9-bit codes is shown below. A local string accumulates pixel color numbers from the palette, with no output action as long as the local string can be found in a code table. There is special treatment of the first two pixels that arrive before the table grows from its initial size by additions of strings.
After each output code, the local string is initialized to the latest pixel color that could not be included in the output code. For clarity the table is shown above as being built of strings of increasing length.
That scheme can function but the table consumes an unpredictable amount of memory. Memory can be saved in practice by noting that each new string to be stored consists of a previously stored string augmented by one character.
It is economical to store at each address only two words: an existing address and one character. The LZW algorithm requires a search of the table for each pixel. A linear search through up to addresses would make the coding slow.
In practice the codes can be stored in order of numerical value; this allows each search to be done by a SAR Successive Approximation Register, as used in some ADCs , with only 12 magnitude comparisons. For this efficiency an extra table is needed to convert between codes and actual memory addresses; the extra table upkeeping is needed only when a new code is stored which happens at much less than pixel rate. Decoding begins by mapping the stored bytes back to 9-bit codes.
These are decoded to recover the pixel colors as shown below. A table identical to the one used in the encoder is built by adding strings by this rule:. Shorter code lengths can be used for palettes smaller than the colors in the example. If the palette is only 64 colors so color indexes are 6 bits wide , the symbols can range from 0 to 63, and the symbol width can be taken to be 6 bits, with codes starting at 7 bits. In fact, the symbol width need not match the palette size: as long as the values decoded are always less than the number of colors in the palette, the symbols can be any width from 2 to 8, and the palette size any power of 2 from 2 to For example, if only the first four colors values 0 to 3 of the palette are used, the symbols can be taken to be 2 bits wide with codes starting at 3 bits.
Conversely, the symbol width could be set at 8, even if only values 0 and 1 are used; these data would only require a 2-color table. Although there would be no point in encoding the file that way, something similar typically happens for bi-color images: the minimum symbol width is 2, even if only values 0 and 1 are used. The code table initially contains codes that are one bit longer than the symbol size in order to accommodate the two special codes clr and end and codes for strings that are added during the process.
As the decoder builds its table it tracks these increases in code length and it is able to unpack incoming bytes accordingly. This technique was introduced originally as a way to avoid patent infringement. Uncompressed GIF can also be a useful intermediate format for a graphics programmer because individual pixels are accessible for reading or painting. This yields a simpler encoding a 1-to-1 correspondence between code values and palette codes but sacrifices all of the compression: each pixel in the image generates an output code indicating its color index.