File format · .xyz
BMP File Format Explained: Structure, Corruption, and Repair
The BMP bitmap format explained: Windows and OS/2 history, file structure, why BMP files turn corrupt, and what recovery can restore.
The BMP format is one of the oldest image formats still in everyday use. It stores picture data in a simple, openly documented layout that grew up alongside Microsoft Windows and OS/2. This page explains how a BMP file is built, why these files stop opening, and what a successful repair can bring back.
What is a BMP file?
A BMP file is a raster image file: a grid of colored dots plus a small amount of bookkeeping needed to display it. BMP stands for bitmap, and Windows documentation calls the internal layout a device-independent bitmap, or DIB. The device-independent part matters. The file describes the image itself, not any particular screen or graphics adapter.
BMP files usually carry the .bmp extension, and occasionally .dib. Web servers and mail systems commonly label them image/bmp or image/x-ms-bmp. Windows uses the format internally, and the same structure appears inside icons, cursors, and data placed on the clipboard. Because the layout has been documented for decades, nearly every image editor, viewer, and browser can open one.
Origins on Windows and OS/2
The bitmap formats are among the oldest image formats on the IBM PC. They arrived with Windows 1.0 in 1985 and evolved alongside it. Windows and OS/2 were developed in tandem in their early years, and their bitmap formats were identical at first, so the format is sometimes called the Windows and OS/2 bitmap format.
The two platforms later diverged, and Microsoft added header variants to support more colors, alpha channels, and color profiles. No version number is stored in the file. A program reads the size of the DIB header, and that size alone tells it which variant it faces.
For years the structures were documented only inside Microsoft's general programming references. A formal, normative specification came later, folded into the Windows Metafile (WMF) specification, which Microsoft placed under its Open Specification Promise.
Inside a BMP file: header, palette, and pixels
A BMP file is a thin wrapper around a DIB. The wrapper is a 14-byte file header whose first two bytes are the ASCII characters BM (hex 42 4D). Those two bytes form the format's signature, and almost every tool checks them before reading further. The header also records the total file size and the byte offset where the pixel data begins.
Next comes the DIB header. Its size varies by variant: 12 bytes in the original core header, 40 bytes in the common BITMAPINFOHEADER, and 108 or 124 bytes in the later V4 and V5 headers. It states the image width and height in pixels, the number of bits per pixel, and the compression method.
Images at 1, 4, or 8 bits per pixel need a color table, a palette mapping each pixel value to a color. Higher depths usually skip it. The pixel array follows the headers. Each row is padded so its length in bytes is a multiple of four, and rows are stored bottom-up by default; a negative height value flips the order.
Most BMP files store pixels uncompressed, which makes them large. The format defines optional run-length compression for 4-bit and 8-bit images, and the V4 and V5 headers can carry alpha channels and color profiles. Because uncompressed files are so redundant, archiving them with ZIP or RAR often shrinks them dramatically.
Formats that borrow the bitmap structure
Windows embeds DIBs in several other file types. ICO icon files and CUR cursor files contain images that begin with a BITMAPINFOHEADER. The clipboard moves images as raw DIB data, without the 14-byte file header. Run-length compressed bitmaps sometimes circulate with an .rle extension. A repair tool that understands BMP therefore understands these relatives too.
Why do BMP files become corrupt or unreadable?
Truncation is the most common fault. A transfer that fails midway, a disk that fills during a save, or a scanner that loses power can leave a file shorter than its header claims. The pixel data simply ends early, so viewers report an unknown or invalid file.
Header damage is the other big category. The file header's offset field and the DIB header's width, height, and size fields must all agree with the data that follows. If a crash or a buggy exporter writes the wrong numbers, the image may refuse to open, or may open skewed, torn, or wrapped into a diagonal smear.
Storage failures play their part as well. Bad sectors, flash wear, and bit rot can punch holes anywhere in the file. So can failed format conversions, malware, and editors that crash mid-save. A damaged palette turns an 8-bit photo into noise even when every pixel survives. And if the first two bytes are no longer BM, many programs reject the file outright without looking further.
What can be recovered from a damaged BMP file?
The odds are usually good, because the real cargo, the pixels, sits at the end of the file and is often intact. When only the 14-byte file header is damaged, recovery is typically complete. The header can be rebuilt from the DIB information below it, and the image returns exactly as it was.
When pixels are missing, partial recovery is the realistic goal. We can usually reconstruct the image up to the point where the file ends or the damage begins. A skewed or diagonal picture, oddly enough, often means every pixel is present and only the width in the header is wrong. That is a fixable fault.
Palette damage on an 8-bit image is recoverable in a different way. The pixel grid survives, and a sensible palette can be inferred or rebuilt so the picture reads correctly again.
How does BMP recovery work?
Repair starts with a survey of what survived. We read the file header and DIB header, check whether the recorded sizes and offsets match the actual bytes on disk, and locate the start of the pixel array. Where a field disagrees with reality, we trust the data and recompute the field.
A missing or unreadable header can be rebuilt. The signature, sizes, and pixel-data offset can all be derived from the surviving DIB information. For a headerless DIB, the classic technique is width recovery. Rows are padded to a multiple of four bytes, so only certain widths are possible for a given bit depth. We test the candidates until the image lines up.
Compressed images add a step. Run-length data must be decompressed carefully, because one corrupted length byte can desynchronize everything after it. We salvage what decodes cleanly and reconstruct affected rows from surrounding image content where possible.
Finally, the recovered image is reassembled as a valid BMP and usually exported to a lossless format such as PNG or TIFF as a stable copy. Geospatial users often pass BMPs through GDAL, the open source raster library supported by the Open Source Geospatial Foundation, so we can return files that drop straight into that workflow.
Frequently asked questions
Is BMP lossless?
Uncompressed BMP is lossless: the pixels you save are the pixels you get back. Run-length compression is lossless too. The format never discards image data the way JPEG does.
Why does my BMP open skewed or diagonal?
That pattern almost always means the stored width does not match the true row length, or the padding is wrong. The pixels are present; the arithmetic that turns them into rows is not. Correcting the header fixes it without touching the pixel data.
Can a completely empty, zero-byte BMP be repaired?
No. A file with no bytes holds nothing to recover. If another copy exists, in a backup, an archive, or on the original media, that copy becomes the starting point.
Are .bmp and .dib files the same thing?
Essentially yes. A .dib file is usually the raw device-independent bitmap without the 14-byte file header. Adding a correct file header turns it into a standard .bmp.
Do all programs read every BMP variant?
Most software handles the 40-bit BITMAPINFOHEADER variant well. The older 12-byte core header and the V4 and V5 extensions are less evenly supported, which is why some files open in one editor and fail in another.
BMP is a sturdy, simple format, and that simplicity works in your favor when a file breaks. If a bitmap will not open, opens wrong, or shows only part of the picture, see our BMP repair service page or send the file for a free evaluation. Our engineers will inspect it, report what is recoverable, and quote the repair before any work begins.
Send us your .xyz file for a free evaluation
Our recovery engineers will tell you exactly what can be recovered — at no cost. There is no charge if we cannot recover your data.
Start a free evaluation