Why Does BMP to PNG Conversion Stay Lossless?
5 min read
The same image, two very different files
When you convert a BMP file to PNG, something interesting happens: the file shrinks noticeably but not a single pixel of the image changes. Most people seeing this for the first time develop a justified suspicion — if you are making something smaller, don't you have to give something up?
The answer is no, and this article explains exactly why.
There are two kinds of compression
The source of the confusion is that the word "compression" is used for two completely different operations.
Lossy compression saves space by reducing data. This is what JPG does: exploiting the properties of the human visual system, it calculates and discards information that is hard for the eye to notice. The file shrinks a great deal, but the discarded data is permanently gone. Opening the JPG again and saving it in another format does not bring that data back.
Lossless compression does not reduce data; it merely expresses the same data more briefly. It is easy to think about with a text example: writing "10 a's" instead of "aaaaaaaaaa" takes up less space but loses no information. When you open it, you can reconstruct the original exactly.
PNG belongs to the second group. BMP is lossless too — it simply performs no compression at all. So going from BMP to PNG is a lossless-to-lossless transition, and the only thing that changes is how the data is packaged.
Why doesn't BMP compress at all?
BMP's design philosophy is built on simplicity. The file starts with a short header block, after which the pixel values are written out in sequence. What is in the image has no effect at all on file size; the size is entirely the product of width, height and bit depth.
The concrete consequence: a completely flat white square and a complex photograph of the same dimensions take up almost identical space as BMP files. Repetition, order or simplicity in the content is never taken into account.
The specification defines a compression scheme called RLE, but it is almost never used in practice and applies only to low bit depths. The overwhelming majority of BMP files you encounter are raw.
There was a rationale for this simplicity: requiring no decoding. Even a very constrained processor can read a BMP directly and push it to the screen. Today that advantage is meaningful only for embedded systems and industrial devices; on the desktop and the web it is entirely worthless.
How does PNG shrink the same pixels?
PNG's work happens in two stages, and both preserve the information.
Stage one: prediction. Instead of writing every pixel as it is, PNG writes how much it differs from its neighbour. Because neighbouring pixels in images are usually very similar, those differences are small numbers, and small numbers take up less space. In a photograph of the sky, for example, the colour changes very slowly as you move horizontally; PNG can express that slow change as "almost the same".
Stage two: pattern compression. A general-purpose lossless compression pass is run over the resulting difference data. This stage finds repeating sequences and shortens them. The grey toolbar in a screenshot, the flat colour area in a logo, the white background of a diagram — all of these deliver big gains here.
What both stages have in common is that they are reversible. When you open the file, the operations are run in the opposite direction and all of the original pixel values are reconstructed.
What does this mean in practice?
You do not need to keep the original. After converting the BMP to PNG, the PNG contains all the information the BMP carried. There is no informational advantage to archiving the source file. The one exception is if you need to give the file to a program that accepts only BMP.
There is no quality concern. You do not need to pick a quality setting, experiment with settings, or zoom in hunting for artefacts. The result is identical to the source anyway.
Repeated operations do not accumulate degradation. In JPG, opening and saving a file adds a little more degradation each time. In PNG there is no such accumulation; you could open and save the file a hundred times and the image would not change. This is an important guarantee for files that will be worked on.
The gain depends on the content. Screenshots, interface captures, logos, diagrams and scanned text shrink dramatically in PNG. For noisy, densely textured photographic content the gain is more modest, because there is little pattern for PNG to find. If you run into that, consider that your content is in fact photographic and that JPG may be a more appropriate target for sharing purposes.
Does the compression apply in memory too?
A frequently asked question: is a PNG small when it is open as well?
No. Compression concerns only the representation on disk. When you open an image, the program decodes the file and places the pixels in memory in raw form; at that point it occupies the same space in memory as the BMP. PNG's advantage is on the storage and transfer side: less disk space, faster downloads, files that fit into an email.
In summary
BMP and PNG are two formats that store the same information; the difference is how they write it. BMP writes everything raw, while PNG uses patterns to express the same thing far more briefly. Because no data is discarded in the conversion between them, the answer to "what do I lose" is clear: nothing. What you gain is disk space, portability and a format that works everywhere.
Frequently Asked Questions
If compression is happening, how can it be lossless?
Because there are two different kinds of compression, and confusing them is a common misconception. Lossy compression saves space by calculating and discarding information the eye barely notices, and the discarded data does not come back. Lossless compression discards no information at all; it merely expresses the same information more briefly. PNG belongs to the second group: it rewrites the data using repeating patterns and the similarity between neighbouring pixels, and reconstructs the whole original when you open it.
Is a PNG file smaller in memory too when it is opened?
No, compression concerns only the representation on disk. When you open a PNG file, the program decodes it and places the pixels in memory in raw form; at that point it occupies the same space in memory as the BMP would. So PNG's advantage is on the storage and transfer side: less disk space, faster loading, easier sharing. In terms of display performance you will not experience any meaningful difference between the two formats in practice.
If I convert the PNG back to BMP, will it be identical to the original file?
In terms of pixel data yes, but the files may not be byte-for-byte identical. The colour value of every pixel in the image is preserved, so you get an exact match visually and as data. However, file headers, bit-depth layout, row padding and any metadata may be written differently. So the result is the same image, but do not expect the two files to match exactly in a comparison program.
How much smaller does the PNG version of the same image get?
That depends entirely on the image's content and it is impossible to give a fixed ratio. For images with flat colour areas, repeating patterns and a limited colour palette — screenshots, logos, diagrams and the like — the gain is very pronounced. For noisy, densely textured or photographic content there is little pattern for PNG to find and the reduction is more modest. Even so, against an uncompressed BMP, PNG is almost always considerably smaller.
Try this out right away with BMP → PNG Dönüştür.
Try BMP → PNG Dönüştür