Understanding how to calculate and interpret bitmap (BMP) file sizes. A Bitmap (BMP) file is a raster graphics image format widely used on Windows platforms. It stores pixel data in an uncompressed or lightly compressed form, making it simple to read but often large in size. Because the format is straightforward, it is a popular teaching example for imageprocessing concepts. The total file size is the sum of the file header, the DIB header (also called the bitmap info header), optional color tables, and the pixel array. General formula: Where: The pixel array size is the most critical part, because BMP stores each row (scan line) aligned on a 32bit boundary. The formula for a single scan line: Then: When Parameters: Row size calculation: Pixel array size: Full file size: Parameters: Row size: Pixel array size: Total file size: Row size is simply width4 because 32bpp already aligns to 4byte boundaries: Pixel array size: File size (no palette):BMP Sizing Data
What is a BMP file?
How to calculate BMP file size
FileSize = HeaderSize + DIBHeaderSize + PaletteSize + PixelArraySize
RowSize = floor((bitsPerPixel * width + 31) / 32) * 4PixelArraySize = RowSize * heightHeader details
Component Offset (bytes) Length (bytes) Description BMP Header 0 14 Signature (BM), file size, reserved fields, offset to pixel data. DIB Header (BITMAPINFOHEADER) 14 40 Image width, height, planes, bitsperpixel, compression, image size, resolutions, palette entries, important colors. Color Table (optional) 54 Variable Present for 8bpp images; each entry 4 bytes (B,G,R,0). Pixel Array Variable Variable Actual bitmap data stored bottomup unless negative height. bitsPerPixel is 24 or 32, the color table is omitted. For 1, 4, and 8bpp images the palette must be present, adding 4(2^bpp) bytes.Pixel data organization
B, G, R (blue first). For 32bpp an extra alpha byte follows (often unused).Practical examples
Example 1 800600, 24bpp (true colour)
RowSize = floor((24 * 800 + 31) / 32) * 4 = floor((19200 + 31) / 32) * 4 = floor(19231 / 32) * 4 = floor(600.96875) * 4 = 600 * 4 = 2400 bytesPixelArraySize = 2400 * 600 = 1440000 bytesFileSize = 14 (file header) + 40 (DIB) + 0 (palette) + 1440000 = 1440054 bytesExample 2 128128, 8bpp (256color palette)
RowSize = floor((8 * 128 + 31) / 32) * 4 = floor((1024 + 31) / 32) * 4 = floor(1055 / 32) * 4 = floor(32.96875) * 4 = 32 * 4 = 128 bytesPixelArraySize = 128 * 128 = 16384 bytesFileSize = 14 + 40 + 1024 + 16384 = 17462 bytesExample 3 1024768, 32bpp (with alpha)
RowSize = 1024 * 4 = 4096 bytesPixelArraySize = 4096 * 768 = 3145728 bytesFileSize = 14 + 40 + 3145728 = 3145782 bytesBest practices for managing BMP size
