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. Pixel data
.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)

Pixel data

The pixels start at the offset given by bfOffBits in the file header. Without compression they are stored as rows, each padded to a multiple of 4 bytes, normally from the bottom of the picture to the top. This page describes uncompressed pixels; compression covers the rest.

00000036  FF 00 00 00 FF 00 00 00 00 00 FF FF FF FF 00 00
Two 24-bit rows of 2 pixels, each padded from 6 bytes to 8

Row size

Each row is rounded up to a whole number of 4-byte words. The number of bytes in a row, often called the stride, is:

const stride = Math.floor((bitCount * width + 31) / 32) * 4;
The number of bytes in one row, padding included

The padding bytes should be zero and are ignored when reading. The size of the pixel data is stride × |height|, which is what biSizeImage holds when it is set.

Bit countWidthBits of pixelsStridePadding
110104 bytes2 bytes and 6 bits
45204 bytes1 byte and 4 bits
85408 bytes3 bytes
163488 bytes2 bytes
2437212 bytes3 bytes
3239612 bytesnone, ever

Row order

When the height in the DIB header is positive, the first row in the file is the bottom row of the picture and the last row is the top. When the height is negative, the rows run from the top down, like most other formats. Pixels within a row always run from left to right.

To find the row that is drawn at line y from the top of a bottom-up image, read row height − 1 − y of the data.

Pixels at each bit depth

Bit countEach pixel isPacking
1an index into a 2-colour colour table8 pixels per byte; the highest bit is the leftmost pixel
4an index into a 16-colour table2 pixels per byte; the high nibble is the left pixel
8an index into a 256-colour table1 pixel per byte
16a colour, split by bit masksa little-endian 16-bit number; 5-5-5 by default
24a colour3 bytes: blue, green, red
32a colour, split by bit masksa little-endian 32-bit number; by default the bytes are blue, green, red, unused

Worked examples

1 bit, 10 pixels wide

The pixel values 1 0 1 1 0 0 1 1 1 0 fill the first byte with 10110011 and start the second with 10. The rest of the second byte and two more bytes pad the row to 4.

B3 80 00 00
One 1-bit row of 10 pixels

4 bits, 5 pixels wide

The palette indexes 1 2 3 4 5 pack two to a byte, high nibble first. The last byte holds the fifth pixel and a zero nibble, and one zero byte pads the row to 4.

12 34 50 00
One 4-bit row of 5 pixels

16 bits, 5-5-5

Pure red is 0 11111 00000 00000 in binary, the number 0x7C00. Stored little-endian, the low byte comes first.

00 7C
One 16-bit red pixel

24 bits, 2 by 2

The example at the top of this page holds a 2 by 2 image. The bottom row comes first: blue (FF 00 00) and green (00 FF 00), then 2 bytes of padding. The top row follows: red (00 00 FF) and white (FF FF FF), then its padding. The overview shows the whole 70-byte file.

© 2026 fileformats.org About Contact Made by Lewpen