File Formats
  • Audio
  • Video
  • Images
  • 3D & CAD
  • Documents
  • Data
  • Code
  • System
Images
  • Raster
  • Vector
  • Camera raw
  • Layered projects
  • HDR & scientific
  • Icons
  • Retro
  1. Home
  2. Images
  3. Raster
  4. BMP
  5. BM
  6. DIB header
.BMP
  • Overview
  • Windows bitmap (BM)
    • File header
    • DIB header
    • Colour spaces
    • Colour table
    • Bit masks
    • Pixel data
    • Compression
  • OS/2 bitmap array (BA)
  • OS/2 icon (IC)
  • OS/2 colour icon (CI)
  • OS/2 pointer (PT)
  • OS/2 colour pointer (CP)

DIB header

The device independent bitmap header follows the file header at offset 14. It gives the size of the image, the bits per pixel and the compression. It comes in several versions, and its first field, its own size in bytes, tells a reader which one it is.

00000000  42 4D 46 00 00 00 00 00 00 00 36 00 00 00 28 00
00000010  00 00 02 00 00 00 02 00 00 00 01 00 18 00 00 00
00000020  00 00 10 00 00 00 13 0B 00 00 13 0B 00 00 00 00
00000030  00 00 00 00 00 00
A 40-byte BITMAPINFOHEADER: 2 by 2 pixels, 24 bits, uncompressed

Versions

Each version keeps the fields of the one before it and adds more at the end, apart from the oldest, whose width and height are 16-bit. Read the size, then read the fields that version has.

SizeNameFromAdds
12BITMAPCOREHEADERWindows 2.0, OS/2 1.x16-bit width and height, planes, bit count
16OS22XBITMAPHEADER, short formOS/2 2.x32-bit width and height; the remaining fields are taken as zero
40BITMAPINFOHEADERWindows 3.0compression, image size, resolution, colours used
52BITMAPV2INFOHEADERAdobe Photoshopred, green and blue masks
56BITMAPV3INFOHEADERAdobe Photoshopalpha mask
64OS22XBITMAPHEADEROS/2 2.xunits, halftoning, colour encoding
108BITMAPV4HEADERWindows 95, NT 4.0masks, colour space, endpoints, gamma
124BITMAPV5HEADERWindows 98, 2000rendering intent, ICC profile

The V2 and V3 sizes are not in Microsoft’s documentation; Photoshop writes them and most readers accept them. BITMAPINFOHEADER is by far the most common, and BITMAPV5HEADER is used for images with alpha or a colour profile. Offsets in the tables below are from the start of the DIB header; add 14 for the offset in the file.

BITMAPCOREHEADER

The original header, 12 bytes long. Rows are always stored bottom row first, the only compression is none, and the colour table uses 3-byte entries.

OffsetSizeTypeNameDescription
04u32bcSizeThe header size, 12.
42u16bcWidthThe width in pixels.
62u16bcHeightThe height in pixels.
82u16bcPlanesThe number of planes, always 1.
102u16bcBitCountBits per pixel: 1, 4, 8 or 24.

BITMAPINFOHEADER

The 40-byte header introduced with Windows 3.0. Width and height become signed 32-bit numbers, and compression and colour counts are added. Every later Windows version starts with these same fields.

OffsetSizeTypeNameDescription
04u32biSizeThe header size: 40, or more for a later version.
44i32biWidthThe width in pixels.
84i32biHeightThe height in pixels. Positive means the rows are stored bottom row first; negative means top row first. See row order.
122u16biPlanesThe number of planes, always 1.
142u16biBitCountBits per pixel: 1, 4, 8, 16, 24 or 32, or 0 when the pixels are an embedded JPEG or PNG.
164u32biCompressionHow the pixels are stored: BI_RGB (0) for uncompressed, or one of the values on the compression page.
204u32biSizeImageThe size of the pixel data in bytes. May be 0 for uncompressed images.
244i32biXPelsPerMeterHorizontal resolution in pixels per metre; 2835 is about 72 dots per inch.
284i32biYPelsPerMeterVertical resolution in pixels per metre.
324u32biClrUsedThe number of entries in the colour table. 0 means the most the bit count allows.
364u32biClrImportantThe number of colours needed to show the image. 0 means all of them.

With BI_BITFIELDS or BI_ALPHABITFIELDS compression, three or four bit masks follow this header.

BITMAPV2INFOHEADER and BITMAPV3INFOHEADER

These sizes move the bit masks inside the header. V2 adds the red, green and blue masks; V3 adds the alpha mask as well.

OffsetSizeTypeNameDescription
040The fields of BITMAPINFOHEADER.
404u32RedMaskThe bits of each pixel that hold red.
444u32GreenMaskThe bits that hold green.
484u32BlueMaskThe bits that hold blue. V2 ends here, at 52 bytes.
524u32AlphaMaskThe bits that hold alpha. V3 ends here, at 56 bytes.

BITMAPV4HEADER

The 108-byte header of Windows 95 and NT 4.0 keeps the four masks and adds colour space information. The masks are used when the compression is BI_BITFIELDS.

OffsetSizeTypeNameDescription
040The fields of BITMAPINFOHEADER, named bV4Size, bV4Width and so on.
404u32bV4RedMaskThe bits that hold red.
444u32bV4GreenMaskThe bits that hold green.
484u32bV4BlueMaskThe bits that hold blue.
524u32bV4AlphaMaskThe bits that hold alpha.
564u32bV4CSTypeThe colour space, such as LCS_sRGB.
6036CIEXYZTRIPLEbV4EndpointsThe red, green and blue primaries, used for a calibrated colour space.
964u32bV4GammaRedRed gamma, as 16.16 fixed point.
1004u32bV4GammaGreenGreen gamma.
1044u32bV4GammaBlueBlue gamma.

BITMAPV5HEADER

The 124-byte header of Windows 98 and 2000 adds a rendering intent and a link to an ICC colour profile, either embedded in the file or named as a separate file.

OffsetSizeTypeNameDescription
0108The fields of BITMAPV4HEADER, named bV5Size and so on.
1084u32bV5IntentThe rendering intent.
1124u32bV5ProfileDataThe offset of the profile, from the start of this header.
1164u32bV5ProfileSizeThe size of the profile in bytes.
1204u32bV5ReservedReserved, zero.

OS22XBITMAPHEADER

OS/2 2.x defined a 64-byte header. Its first 40 bytes line up with BITMAPINFOHEADER, but two compression values differ: 3 means Huffman 1D and 4 means RLE24. A short form keeps only the first 16 bytes, and the missing fields are taken as zero. OS/2 colour tables use 4-byte entries.

OffsetSizeTypeNameDescription
04u32cbFixThe header size, 64 or 16.
44u32cxThe width in pixels.
84u32cyThe height in pixels.
122u16cPlanesThe number of planes, 1.
142u16cBitCountBits per pixel. The short form ends here.
164u32ulCompression0 none, 1 RLE8, 2 RLE4, 3 Huffman 1D, 4 RLE24.
204u32cbImageThe size of the pixel data in bytes.
244u32cxResolutionHorizontal resolution.
284u32cyResolutionVertical resolution.
324u32cclrUsedThe number of colours used.
364u32cclrImportantThe number of important colours.
402u16usUnitsThe resolution units; 0 is pixels per metre.
422u16usReservedReserved.
442u16usRecordingThe row order; 0, bottom row first, is the only value defined.
462u16usRenderingThe halftoning method used, if any.
484u32cSize1The first halftoning parameter.
524u32cSize2The second halftoning parameter.
564u32ulColorEncodingThe colour encoding; 0 is RGB.
604u32ulIdentifierFree for the application’s own use.

Row order

A positive height means the first row in the file is the bottom row of the picture, a bottom-up bitmap. A negative height means the first row is the top row, a top-down bitmap, and the image is |biHeight| rows tall. Top-down bitmaps cannot be compressed: their compression must be BI_RGB or BI_BITFIELDS. The width is always positive.

The pixel data page shows how rows are laid out and padded.

© 2026 fileformats.org About Contact Made by Lewpen