The BMP file format, also known as bitmap image file, the Windows Bitmap file format, or simply bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device (such as a graphics adapter). The underlying device-independent bitmap representation is commonly called a DIB: it consists of a DIB header, optional color information, and pixel data, describing the image independently of the display device; a BMP file wraps such a DIB in an additional 14-byte file header. It originated in the closely linked early development of Microsoft Windows and OS/2, whose bitmap formats were at first identical;; used by the GDI subsystem of both platforms, it is sometimes called the Windows and OS/2 bitmap file format and is usually named with the file extension or .
The BMP file format is capable of storing two-dimensional digital images in various color depths, and optionally with data compression, alpha channels, and color profiles.
The format's simplicity, its familiarity on Windows, and its status as a relatively well-documented, open format have made it very widely supported, so that image-processing programs on many operating systems can read and write BMP files. The same bitmap structure is embedded in related Windows formats: ICO and CUR files, for example, contain images that begin with a . Because uncompressed BMP files hold a great deal of redundant data, they can often be reduced substantially by general-purpose lossless compression such as ZIP or RAR.
The bitmap header structures were documented from the outset in Microsoft's general Windows and OS/2 programmer's references rather than in a specification dedicated to BMP alone; a formal specification of the same structures, using normative language, was only later folded into the Windows Metafile (WMF) specification, which Microsoft placed under its Open Specification Promise.
History The bitmap formats associated with Microsoft Windows are among the oldest image formats on the IBM PC, having originated with the first release of Windows and evolved alongside it — and, for a time, alongside OS/2 — over the following decade. Because the format carries no field recording its header version, the successive variants are distinguished by the size of their header, and an application identifies a variant by reading the header-size field at the start of the bitmap header.
Windows 1.0 (1985) introduced only a simple device-dependent bitmap (DDB) — not yet the device-independent, DIB-based file format described in this article — highly dependent on the output device for which it was created, so a bitmap suited to one display was not necessarily usable on another. A program created such a bitmap through handle-based GDI calls and loaded it from a module's resources; the structure recorded only its width, height, plane count and bits-per-pixel, and the raw bits followed in the device's own format, with no color table of its own.
While these early versions of Windows were being developed, Microsoft shared responsibility with IBM for the first releases of OS/2, whose Presentation Manager graphical interface used a closely related bitmap format. According to the Encyclopedia of Graphics File Formats, support for a programmable color palette was added to both Windows and BMP as Windows 2.x (1987) was being developed, making its DIB format identical to that of OS/2 1.1 (1988). This device-independent bitmap (DIB) emerged from that joint work, and sources differ over which side originated it — and even over when it reached Windows. The Encyclopedia credits Windows itself, with Presentation Manager adopting the format afterward. Other accounts instead trace the DIB to OS/2: Charles Petzold writes that the DIB "is new in Windows 3" and "an extension of the bitmap format supported in the OS/2 1.1 Presentation Manager", and a 1990 BYTE column reported that "DIBs first surfaced in OS/2 1.1 as the Graphics Programming Interface bit map". Raymond Chen, a longtime Microsoft engineer, dates this earlier, to Windows 2.0, stating that "Windows 2.0 adopted OS/2's bitmap format in order to foster interoperability" between the two systems.
That early format used a 12-byte information header — later named — whose leading size field was required to be 12. IBM's own documentation, and that same Microsoft reference, instead name this OS/2 header — the same name Microsoft later gave the unrelated 40-byte structure below. To avoid that collision, some secondary sources instead call the OS/2 1.x and 2.x headers and ; this article uses IBM's own names for them.
Windows 3.0 (1990) carried the device-independent bitmap forward in the form still dominant today, built around a new 40-byte , which superseded the earlier 12-byte header. When written to disk with a , this became the basis of the modern BMP file format. The release also added run-length encoding for 4- and 8-bit-per-pixel (bpp) images ( and ), and still accepted the older 12-byte header, which it documented as a "compatible with … OS/2 Presentation Manager versions 1.1 and 1.2".
OS/2 2.0 (1992) then extended its version independently. The 64-byte widened the dimensions to 32 bits and added 24-bit RLE compression and Huffman 1D compression for bi-level images. OS/2 also defined a bitmap-array container — identified by the signature and holding images tagged , , , or — that could bundle several device-dependent and device-independent renderings of a bitmap, icon or pointer in a single file, the device-independent version first. As the two companies' operating-system efforts diverged, the Windows and OS/2 formats grew steadily further apart.
Windows NT (1993) introduced support for using with 16- and 32-bpp DIBs, with the color masks following the 40-byte header instead of a color table. Two further, historically undocumented header variants of 52 and 56 bytes, which fold those RGB masks (and an alpha mask) into the header itself, are also encountered (described below).
Windows 95 (1995) introduced the 108-byte , later also supported by Windows NT 4.0 (1996), which added an explicit alpha-channel mask together with a color-space identifier, CIE color endpoints and per-channel gamma values, allowing Image Color Matching information to travel with the bitmap. Windows 98 (1998) followed with the 124-byte , later also supported by Windows 2000 (1999), which can embed or link an ICC color profile.
Independently of this header-borne alpha mask (see below), the alpha-blending functions available in Windows 2000 and later could take a per-pixel alpha value directly from a 32-bit image, with no color mask involved.
Rather than being defined in a single specification dedicated to BMP, the format's structures were documented release by release inside the general Windows and OS/2 programmer's references, header files and online help. The later Windows Metafile specification was the first to define these structures formally, in normative language.
Windows bitmap format
The bitmap image file consists of fixed-size structures (headers) as well as variable-sized structures appearing in a predetermined sequence. Many different versions of some of these structures can appear in the file, due to the long evolution of this file format. Some applications create bitmap image files which are not compliant with the Microsoft documentation; not all fields are used, and a value of 0 will be found in these unused fields. All multi-byte integer fields defined by the BMP and Windows/OS/2 bitmap structures — every header field, as well as the color masks — are stored in little-endian byte order, a heritage of the format's origin on Intel-based machines.
A device-independent bitmap (DIB) is a format for defining bitmaps at various color resolutions so that an image can be moved from one device to another independently of the display hardware — hence the "device-independent" in the name. Unlike a device-dependent bitmap, which exists inside the system as a bitmap object, a DIB is an external format, normally transported in metafiles, in BMP files, and on the clipboard (the data format). A BMP file and a bare DIB are not identical, however: the file begins with the 14-byte bitmap file header (), whereas a DIB transported in a metafile or on the clipboard omits that header and begins directly with the DIB header.
Diagram 1 shows the layout of a BMP file using the , the most extensive Windows DIB header — it appears in the diagram because it contains every field added by the successive header extensions. Earlier DIB header variants contain fewer fields, but the structures they define form the initial part of the same layout; the variant actually present in a given file is determined by the DIB header's size field.
In its simplest form, a BMP file contains three structures in sequence: the 14-byte bitmap file header (), which identifies the file and records the offset of the pixel array; a DIB header — most commonly — whose size determines the header variant; and the pixel array, which holds the image data, with each row (scan line) padded to a multiple of four bytes.
Beyond this minimal layout, a file may contain further structures, depending on the pixel format and the header variant: Color masks — RGB masks may follow a when is ; in and later, the masks are stored as header fields. Color table — an array of entries; required for indexed-color images (8 bpp or less) and normally absent at 16 bpp and above. ICC color profile — available only with ; it may be embedded in the file or referenced by a path to an external profile.
Because the pixel array and the optional profile are located by offset fields rather than fixed positions, the format also permits small alignment gaps before them. In practice such gaps are almost always absent.
File header This block of bytes () stands at the start of the file and is used to identify it: an application typically reads it first to confirm that the file is a BMP file and is not damaged.
+ Windows Offset (bytes) Size (bytes) Member Description 0 2 The header field used to identify the file; it must be BM (the ASCII characters "B" and "M", 0x4D42). 2 4 The size of the BMP file in bytes 6 2 Reserved; must be zero 8 2 Reserved; must be zero 10 4 The offset, i.e. starting address, of the byte where the bitmap image data (pixel array) can be found.
DIB header The DIB header records the image's dimensions, color depth, compression method and related properties. It comes in several variants that all begin with a 32-bit size field, which tells an application which variant is present, since Microsoft extended the format several times. The 12-byte is the oldest and simplest variant; the 40-byte introduced with Windows 3.0 is the common format still written today, and and later extend it further.
+ Windows DIB headers Size (bytes) Header name OS support Features 12 OS/2 1.1; Windows 3.0 The original and smallest DIB header; stores width and height as 16-bit values and supports no compression. 40 Windows 3.0 Extends bitmap width and height to 4 bytes. Adds RLE compression. 108 Windows NT 4.0, 95 Adds color space type and gamma correction 124 Windows 2000, 98 Adds a rendering intent and ICC color profiles
The 12-byte — identical to the OS/2 1.1 header (detailed below) — contains:
+ Windows Offset (bytes) Size (bytes) Member Description 14 4 The size of this header, in bytes (12) 18 2 The bitmap width in pixels (unsigned 16-bit) 20 2 The bitmap height in pixels (unsigned 16-bit) 22 2 The number of color planes (must be 1) 24 2 The number of bits per pixel
For compatibility reasons, most applications write the older , which remains the common Windows format; it is described in the next table. Unless explicitly noted, the members in this table are unsigned integers.