File types · Explainer

The BMP file (.bmp)

A BMP file is the Windows bitmap: a simple image format that usually stores every pixel uncompressed, exactly as it sits in memory. This guide explains what's inside one, its header versions and quirks, why the files are so large, and has free sample BMP files to download for testing.

At a glance

Full name
Windows Bitmap, also called a device-independent bitmap (DIB)
Extensions
.bmp; .dib is the same format
MIME type
image/bmp, registered in 2016 (RFC 7903); image/x-ms-bmp and image/x-bmp turn up in older software
Kind
Binary raster image, usually uncompressed; optional lossless run-length encoding
Standard or owner
Microsoft; documented in the Windows SDK and, since 2007, under Microsoft's Open Specification Promise
First released
Late 1980s, with Windows and IBM and Microsoft's OS/2; today's common form came with Windows 3.0 in 1990
Colours
1, 4 or 8 bits per pixel with a palette; 16, 24 or 32 bits direct colour; alpha in 32-bit files, with patchy support
Compression
Usually none; RLE8 and RLE4 for palette images
Max size
Width and height are 32-bit signed numbers; the file-size field limits a file to 4 GB
Magic number
42 4D (BM), followed by the file size in 4 bytes
Opens with
Every web browser, Windows Paint and Photos, macOS Preview and almost every image editor

The basics

What is a BMP file?

A BMP file stores a picture as a grid of pixels, almost always without compression. Microsoft and IBM designed it in the 1980s for Windows and OS/2, so that a program could load an image straight into memory and draw it on screen with very little processing. The file layout is the in-memory layout Windows uses for a device-independent bitmap (DIB), with a small file header in front.

That simplicity is both BMP's strength and its weakness. Any program can read and write it with a few dozen lines of code, and decoding is close to free. But the files are big: our 640 × 400 sample-24bit.bmp is 768,054 bytes, while the same picture is 458,129 bytes as PNG (lossless) and 41,904 bytes as a quality-85 JPEG.

Where you still meet BMP:

  • Inside Windows: the clipboard passes images as DIBs, and icons (.ico) and cursors (.cur) store their images as BMP-style bitmaps (or PNGs) without the file header.
  • Embedded devices and hobby electronics: small screens, printers and microcontrollers often read BMP because it needs no decompression library.
  • Older software and test pipelines: scientific instruments, image-processing tutorials and legacy business apps.

It's a poor choice for the web or for sending images to people, even though every browser shows it: PNG is lossless too and usually much smaller.

Anatomy

What's inside a BMP file

A BMP file is a 14-byte file header, an information header (40 bytes in most files), an optional colour table, then the pixels, row by row. All numbers are little-endian: the least significant byte comes first. Below is every byte of sample-3x2.bmp, a 24-bit image 3 pixels wide and 2 high: red, green and blue on top; black, grey and white below.

sample-3x2.bmp (hex, 78 bytes)
42 4D  4E 00 00 00  00 00  00 00  36 00 00 00

28 00 00 00  03 00 00 00  02 00 00 00  01 00  18 00
00 00 00 00  18 00 00 00  13 0B 00 00  13 0B 00 00
00 00 00 00  00 00 00 00

00 00 00  80 80 80  FF FF FF  00 00 00
00 00 FF  00 FF 00  FF 00 00  00 00 00
  1. 142 4D

    The signature

    BM in ASCII, for bitmap. Old OS/2 files can also start with BA, CI, CP, IC or PT, for bitmap arrays, icons and pointers.

  2. 24E 00 00 00

    File size

    0x4E = 78 bytes, the whole file. Many readers don't check it, and some writers get it wrong.

  3. 300 00 00 00

    Reserved

    Two 2-byte fields, usually zero.

  4. 436 00 00 00

    Pixel data offset

    The pixels start at byte 54 (0x36): 14 bytes of file header plus 40 bytes of information header, with no colour table in between.

  5. 528 00 00 00

    Header size, and so its version

    40 (0x28): a BITMAPINFOHEADER. There's no version number in a BMP; readers tell the versions apart by this size.

  6. 603 00 00 00 02 00 00 00

    Width and height

    3 pixels wide, 2 high. The height is positive, which means the rows are stored bottom-up: the bottom row of the picture comes first in the file. A negative height means top-down.

  7. 701 00 18 00

    Planes and bit depth

    Planes is always 1. 0x18 = 24 bits per pixel: one byte each for blue, green and red, with no palette.

  8. 800 00 00 00 18 00 00 00

    Compression and image size

    Compression 0 is BI_RGB, meaning none. The pixel data is 24 bytes: 2 rows of 12.

  9. 913 0B 00 00 13 0B 00 00

    Resolution

    0x0B13 = 2,835 pixels per metre in each direction, which is 72 DPI. Only used when printing; most software ignores it.

  10. 1000 00 00 00 00 00 00 00

    Colours used and important

    Both 0: there's no palette, and every colour matters.

  11. 1100 00 00 80 80 80 FF FF FF 00 00 00

    The first row in the file: the bottom row

    Black, grey and white, 3 bytes each. That's 9 bytes, and every row must be a multiple of 4 bytes long, so 3 bytes of padding (00 00 00) follow.

  12. 1200 00 FF 00 FF 00 FF 00 00 00 00 00

    The second row: the top row

    Red, green and blue, each stored in blue, green, red order: red is 00 00 FF. Then 3 more padding bytes.

Under the hood

How BMP stores pixels: bottom-up rows, padding and BGR

Three rules explain most BMP bugs:

  1. 1Rows are stored bottom-up. With a positive height, the first row in the file is the bottom row of the picture. A negative height means top-down, the order almost every other format uses. Compressed BMPs must be bottom-up.
  2. 2Every row is padded to a multiple of 4 bytes. A 24-bit image 301 pixels wide has 903 bytes of pixels per row, so each row gets 1 byte of padding, making 904. A reader that forgets the padding draws a picture that slants diagonally.
  3. 3Colours are in blue, green, red order, and 32-bit pixels are blue, green, red, then an unused byte or alpha. Read them as RGB and red and blue swap.

The size of a row (the stride) is the row's bits rounded up to a whole number of 32-bit words:

stride.js
// bytes per row, padding included
const stride = Math.floor((width * bitsPerPixel + 31) / 32) * 4;
const pixelDataSize = stride * Math.abs(height);

Images with 1, 4 or 8 bits per pixel have a colour table (palette) between the header and the pixels: up to 2, 16 or 256 entries of 4 bytes (blue, green, red, zero). The pixels are then palette numbers, packed several to a byte at 1 and 4 bits.

Versions

BMP header versions

BMP has no version number. Instead, the information header grew as Windows did, and a reader tells the versions apart by the header's size, the first 4 bytes after the file header. Each Windows version adds fields to the end of the previous one.

SizeNameFromWhat it adds
12BITMAPCOREHEADEROS/2 1.x; still read by WindowsWidth and height as 16-bit numbers, bit depth. Colour table entries of 3 bytes.
40BITMAPINFOHEADERWindows 3.0 (1990)32-bit signed width and height, compression (RLE4, RLE8), image size, resolution, palette size. By far the most common.
64OS/2 2.x headerOS/2 2.0 (1992)Its own extensions, such as Huffman 1D and 24-bit RLE compression. Rare today.
52, 56V2 and V3 info headersNever officially documentedRed, green, blue (and alpha) bit masks inside the header. Written by some Adobe software.
108BITMAPV4HEADERWindows 95 and NT 4.0Colour masks including alpha, a colour space type, colour endpoints and gamma.
124BITMAPV5HEADERWindows 98 and 2000A rendering intent and an embedded or linked ICC colour profile.

Many programs write the 40-byte header for ordinary images and a V4 or V5 header when they need alpha or colour management. Our sample-32bit-alpha.bmp uses a V5 header with an alpha mask and the sRGB colour space.

Formats

Bit depths and compression

Bits per pixelColoursNotes
12, from a paletteBlack and white, or any two colours
416, from a paletteCan use RLE4 compression
8256, from a paletteCan use RLE8 compression
1632,768 or 65,5365 bits per channel by default (555); with BI_BITFIELDS, masks can define 565
24About 16.7 millionBlue, green, red: the usual "24-bit bitmap" that Paint saves
32About 16.7 million, plus alphaBlue, green, red and a fourth byte that is either unused or alpha

The compression field (offset 30) is usually BI_RGB (0): none. The other values:

  • BI_RLE8 (1) and BI_RLE4 (2): run-length encoding for 8- and 4-bit images. Runs of one colour are stored as a count and a palette index. Our sample-rle8.bmp, a flat-colour chart, is 11,948 bytes; uncompressed, the same 640 × 400 image would take 257,078 bytes. On photos, RLE barely helps.
  • BI_BITFIELDS (3): not compression but a description of the pixel layout, with bit masks saying where red, green, blue (and in V4 and V5 headers, alpha) sit in each 16- or 32-bit pixel.
  • BI_JPEG (4) and BI_PNG (5): a JPEG or PNG image in place of the pixels. Windows only accepts these when sending images to a printer, so you won't meet them in files.

Comparison

BMP vs PNG, JPG and TIFF

BMPPNGJPGTIFF
CompressionUsually noneLosslessLossyNone, lossless or lossy
Our 640 × 400 picture768,054 bytes458,129 bytes41,904 bytes (quality 85)Depends on the compression
Transparency32-bit only, patchy supportYesNoYes
MetadataNone (just resolution and colour space)Text, ExifExif, XMP, ICCExif, XMP, IPTC, ICC
BrowsersAllAllAllSafari only
Best forSimple programs and devicesScreenshots, graphicsPhotosPrint, scans, archives

Converting a BMP to PNG loses nothing and almost always makes the file smaller; for flat graphics like sample-rle8.bmp the PNG is 2,093 bytes. The one advantage BMP keeps is that it needs no decompression, which matters on tiny devices, not on computers or phones.

Troubleshooting

Upside down, slanted, wrong colours: common BMP problems

  • The image is upside down. A reader ignored the sign of the height: it read a top-down file as bottom-up, or the other way round. Test with sample-top-down.bmp, whose arrow must point up.
  • The image slants or is striped diagonally. The reader didn't skip the row padding. It only shows when the width times the bytes per pixel isn't a multiple of 4, which is why sample-top-down.bmp is 301 pixels wide.
  • Red and blue are swapped. The pixels were read as RGB instead of BGR.
  • The transparent areas are black or white. Many programs treat the fourth byte of a 32-bit pixel as unused, especially with the 40-byte header. A V4 or V5 header with an alpha mask is the most widely understood way to store alpha, and support is still uneven. For transparency, use PNG.
  • 16-bit colours look green or purple. 555 and 565 layouts were mixed up; the bit masks say which one the file uses.
  • The file is huge. It's uncompressed. Convert to PNG for an exact copy at a fraction of the size.

How to

How to open, edit and convert a BMP file

  • Open it: double-click. Windows Photos and Paint, macOS Preview, Linux image viewers and every browser show BMPs.
  • Edit it: Paint, GIMP, Photoshop, Paint.NET or any image editor. Paint's Save as > BMP offers monochrome, 16-colour, 256-colour and 24-bit; GIMP's export dialog offers RLE and 16, 24 and 32-bit layouts.
  • Convert to PNG or JPG: File > Export in Preview, Save as in Paint, or magick image.bmp image.png with ImageMagick.
  • Make a BMP for an old program: magick image.png BMP3:image.bmp writes the plain 40-byte header that old readers expect; for a device that needs 24-bit, add -type TrueColor.
  • Inspect it: identify -verbose image.bmp (ImageMagick) shows the size, bit depth and compression, and file image.bmp the header version; the headers are short enough to read in any hex editor.

Security

Is it safe to open a BMP file?

Yes, in general. A BMP has no scripts, macros or links, and RFC 7903, which registered image/bmp, describes bitmaps as having "a mostly unremarkable security history". Two cautions remain:

  • Malformed headers. A file can claim dimensions, offsets or palette sizes that don't match its contents. Decoders that trust those numbers have had bugs; keep your software updated, and check dimensions before decoding uploaded files, since a small RLE file can declare a very large image.
  • A BMP that isn't one. A file named image.bmp.exe is a program, not an image. Windows hides known extensions by default, so turn them on in File Explorer.

On privacy, BMP is unusually clean: there's no Exif, no GPS and no text field, so a BMP carries only its pixels, size, resolution and colour space.

Free downloads

Sample BMP files to download

Free sample BMP files covering the common header versions, bit depths and quirks: 24-bit, 8-bit palette, RLE8, 32-bit with alpha, top-down rows with padding, and a 78-byte file you can read byte by byte. Every one decodes identically in Pillow, ImageMagick and FFmpeg.

sample-24bit.bmp · 750.1 KBDownloadOpen
The sample file sample-24bit.bmp

What's inside sample-24bit.bmp

sample-24bit.bmp is the kind of file Windows Paint saves: 24 bits per pixel, a 40-byte header, bottom-up rows. Open it in a hex editor to find these parts.

  1. File header: BM, 768,054 bytes, offset 54

    The signature, the total file size and where the pixels start.

  2. BITMAPINFOHEADER (40 bytes)

    640 wide, height +400 (bottom-up), 1 plane, 24 bits per pixel, compression 0 (BI_RGB), 768,000 bytes of pixels, 72 DPI.

  3. No colour table

    24-bit images store colours directly, so the pixels start straight after the header.

  4. 400 rows of 1,920 bytes

    640 pixels × 3 bytes is already a multiple of 4, so these rows need no padding. The first row in the file is the bottom of the picture: the lake.

  5. BGR byte order

    Each pixel is blue, green, red. The sky near the top of the picture is at the end of the file.

  6. No metadata

    BMP has nowhere to put text, so the "99helpers sample" note is drawn into the image itself.

All sample BMP files

  • 24-bit BMP

    sample-24bit.bmp · 750.1 KB (768,054 bytes)

    A 640 × 400 synthetic landscape, 24 bits per pixel, BITMAPINFOHEADER, bottom-up rows, no compression: the most common kind of BMP.

    • Checking an app or upload form accepts BMP
    • Testing conversion to PNG or JPEG
  • Tiny 3 × 2 BMP (78 bytes)

    sample-3x2.bmp · 78 bytes

    Six pixels: red, green, blue over black, grey, white. Every byte is explained in the anatomy above, padding included.

    • Learning the format in a hex editor
    • Unit tests for BMP readers and writers
  • 8-bit palette BMP

    sample-8bit-palette.bmp · 251.1 KB (257,078 bytes)

    A 640 × 400 landscape reduced to 256 colours with dithering, with a 1,024-byte colour table before the pixels (offset 1,078).

    • Decoder tests for palette images
    • Checking palette conversion to RGB
  • RLE8-compressed BMP

    sample-rle8.bmp · 11.7 KB (11,948 bytes)

    A 640 × 400 flat-colour bar chart with an 8-colour palette, compressed with BI_RLE8: encoded runs, absolute runs and end-of-line codes.

    • Testing RLE8 decoding
    • Checking thumbnailers handle compressed BMPs
  • 32-bit BMP with alpha (V5 header)

    sample-32bit-alpha.bmp · 250.1 KB (256,138 bytes)

    320 × 200 artwork with a soft shadow, translucent circles and an opacity ramp, in BGRA with a 124-byte BITMAPV5HEADER, BI_BITFIELDS masks including alpha, and the sRGB colour space.

    • Checking whether an app reads BMP transparency
    • Testing V5 header support
  • Top-down BMP with row padding

    sample-top-down.bmp · 176.6 KB (180,854 bytes)

    301 × 200, 24-bit, with a negative height so rows run top to bottom. Each 903-byte row has 1 byte of padding. The arrow should point up and the edges should be straight.

    • Catching readers that ignore negative heights
    • Catching readers that ignore row padding

Ways to test with them

  • Orientation: open sample-top-down.bmp in your app or pipeline. If the arrow points down, it ignores the sign of the height.
  • Row padding: in the same file, a slanted image or a diagonal seam means the 1 byte of padding per row isn't skipped.
  • Transparency: put sample-32bit-alpha.bmp on a dark background. A black or white box means the alpha mask was ignored.
  • Compression support: some minimal readers only handle BI_RGB; sample-rle8.bmp shows whether yours handles RLE8.
  • Byte-exact readers: compare your parser's output for sample-3x2.bmp with the six colours listed above.

Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.

Put it online

Have a BMP file? Give it a link.

Drop a BMP on 99helpers and it gets its own web address. Anyone who opens the link sees the image straight away in their browser, at full quality, with nothing to download or convert.

Questions

BMP files, frequently asked

What is a BMP file?

A Windows bitmap: an image format that stores pixels, usually uncompressed, in the same layout Windows uses in memory. Every browser and image editor can open it.

Why are BMP files so big?

Because most are uncompressed: a 24-bit BMP takes 3 bytes per pixel, plus padding. A 12-megapixel photo is about 36 MB as BMP. PNG stores the same pixels exactly in much less space.

Is BMP lossless?

Yes. Uncompressed and RLE-compressed BMPs keep every pixel exactly. Converting from a lossy format like JPEG to BMP doesn't restore lost detail, though.

Does BMP support transparency?

Partly. 32-bit BMPs can carry an alpha channel, most reliably with a V4 or V5 header that declares an alpha mask, but many programs ignore it. Use PNG when transparency matters.

How do I convert BMP to PNG or JPG?

Open it in Paint, Photos or Preview and save or export as PNG or JPEG, or run magick image.bmp image.png. PNG keeps every pixel; JPEG makes a much smaller, slightly lossy copy.

Why is my BMP upside down?

BMP rows are normally stored bottom-up, and a negative height means top-down. A program that gets this wrong shows the image upside down.

What's the difference between BMP and DIB?

Nothing in the file. DIB (device-independent bitmap) is the in-memory structure; a .bmp or .dib file is that structure with a 14-byte file header in front.

Can I use BMP images on a website?

Browsers show them, but they're many times larger than PNG, JPEG or WebP and slow pages down. Convert them before publishing.

Related formats

Other file types explained

Keep going

Related

Sources

Last reviewed 27 October 2026.