File format · .vax

PBMPlus Files: PBM, PGM and PPM Image Format and Repair Guide

The PBMPlus and netpbm family, PBM, PGM and PPM, is a simple uncompressed image format. Here is how it works, why files break, and how repair is done.


A PBMPlus file is one of the plainest raster image formats still in regular use. The family has three members, PBM, PGM and PPM, which store black and white, grayscale, and color pictures in a layout simple enough to parse in a few dozen lines of code. That simplicity is also why damaged files are often recoverable. This page explains the format, the ways these files break, and what repair can realistically bring back. If you were looking for pharmacy benefit managers, which share the PBM abbreviation, this is not that topic.

What is a PBMPlus file?

The name comes from PBMPlus, a free image conversion toolkit written by Jef Poskanzer and distributed in the late 1980s, with its final release in 1991. In 1993 development resumed under the name netpbm, and that open source project still defines the formats today.

Each format covers one kind of image. PBM, the portable bitmap, stores pure black and white pixels. PGM, the portable graymap, stores grayscale values up to 16 bits deep. PPM, the portable pixmap, stores full color with red, green and blue samples for every pixel.

The three are often spoken of together as PNM, short for portable anymap, and you will see .pbm, .pgm, .ppm and .pnm extensions in the wild. Netpbm later added PAM, magic number P7, a generalization that can carry monochrome, gray, color and alpha data in one container.

These formats were never meant as archives. They serve as a common currency between conversion tools: quick to write, quick to read, and byte for byte identical on every system.

Which programs create and open these files?

The netpbm suite itself contains hundreds of small converters with names like pnmtopng and pnmtops, each reading one format and writing another. On Linux and Unix systems the family has long served as a lingua franca for scripted image processing.

Support reaches well beyond that. ImageMagick, GraphicsMagick, GIMP and XnView all read and write the formats, and many lesser known viewers do too. Scanners, ray tracers and scientific software from the 1990s emitted PPM directly, which is why archives still hold large batches of these files today.

Inside the file: magic numbers and raster data

Every file begins with a two character signature in plain ASCII: the letter P followed by a digit. The digit names both the format and the flavor.

Magic Format Encoding
P1 Portable bitmap Plain ASCII
P2 Portable graymap Plain ASCII
P3 Portable pixmap Plain ASCII
P4 Portable bitmap Raw binary
P5 Portable graymap Raw binary
P6 Portable pixmap Raw binary

The header continues with the width and height written as decimal text, separated by whitespace. PGM and PPM files add a maxval, a decimal number from 1 to 65,535 that defines the top of the sample range. A single whitespace character closes the header, and pixel data follows immediately.

Comments may appear in the header: a hash mark starts one, and it runs to the end of the line. Some programs stamp their name there, which is harmless.

The two flavors differ in how pixels are written. In the plain flavors, pixels appear as decimal numbers separated by spaces, and the specification asks that no line exceed 70 characters. In the raw flavors, samples are bare bytes: a raw PGM uses one byte per pixel when maxval is under 256, and two bytes, most significant first, when it is not. A raw PPM writes red, green and blue for each pixel in turn. A raw PBM packs eight pixels per byte, pads every row to a byte boundary, and treats 1 as black.

Nothing is compressed, nothing is checksummed, and there is no metadata block. A file is a small text header followed by an exact, uncompressed image. Web servers commonly label the types image/x-portable-bitmap, image/x-portable-graymap and image/x-portable-pixmap. The netpbm project's own documentation is the authoritative reference for all details above.

Why do PBM, PGM and PPM files become unreadable?

The classic killer is a text mode transfer. Raw flavors are binary, but some copy and transfer tools treat any file as text, converting line feeds to carriage return pairs or halting at a stray byte valued 26. The file then grows or shrinks, and every row after the damage point shifts.

Truncation is just as common. A disk fills, a copy is interrupted, and the header promises more rows than the file contains. Viewers that trust the header report the file as broken instead of showing the part that survives.

Header damage produces subtler symptoms. A width that is off by a few pixels tears the picture into diagonal slivers. A corrupted maxval turns a photo solid black or blows it out to white. Either way, the pixel data itself may be perfectly intact.

Files that traveled through email or scripts sometimes arrive with extra text wrapped around them, or arrive encoded when the recipient expected raw bytes. Others were simply renamed with the wrong extension somewhere in their life. Ordinary media failure adds its share: bad sectors and partial disk rescues leave holes scattered through the raster.

What can a damaged file still give up?

Because the raster is uncompressed and stored in reading order, every surviving byte is a real pixel or color component. There is no compression dictionary to rebuild and no keyframe that later data depends on.

A file cut off partway down yields every complete row above the cut. We rebuild the header around the rows that exist, and you recover the top of the picture exactly. A skewed image is usually fully present too: the bytes are all there, and only the declared width is wrong.

A hole in the middle costs exactly the pixels that once lived there. Everything around it survives untouched, since no pixel depends on any other.

Honest limits apply. No repair can conjure pixels the file never contained. If an overwrite destroyed a region, that region is gone; what surrounds it is not.

How do we repair a PBMPlus file?

Repair starts with the header. We confirm the magic number, parse the dimensions and maxval, and compute the exact raster length the header implies. For a raw PPM with maxval under 256 that is three bytes per pixel; for a raw PBM it is the padded byte width of each row times the height.

That arithmetic also runs in reverse. When a header is missing or unreliable, the file size alone often narrows the true dimensions, because the raster length must factor into width times height. A one pixel change in width shifts everything, so the correct value announces itself.

We then rebuild or correct the header and salvage every complete row. Special cases get individual handling: stripping text a mail system wrapped around the file, undoing the regular damage a text mode transfer leaves, and reinserting a header when only the raster survived. The repaired result is validated against the specification and rendered for visual inspection.

We usually return the image in its original form plus a PNG or TIFF copy, so what you archive going forward is compressed and checksummed. What we cannot do is invent rows that were never written to disk. What we can do is extract every pixel the file still holds.

A few habits that prevent most of this damage

Transfer these files in binary mode, always. Keep a lossless copy in PNG or TIFF for long term storage, since those containers are smaller and verified. Convert plain ASCII variants before archiving, because text files invite well meaning editors. None of this takes long, and it removes nearly every failure mode listed above.

Frequently asked questions

Is PNM a fourth format?

No. PNM, portable anymap, is a collective term for PBM, PGM and PPM, and a .pnm extension simply means one of the three. Tools detect the actual type from the magic number, never from the file name.

Why does my image open as diagonal stripes?

Almost always a wrong width in the header. All the rows are present, but each one starts a few pixels early or late. Recomputing the true width from the raster size fixes the picture without touching a single pixel.

Can a file with no header at all be recovered?

Often, yes. If the raster bytes survive, the arithmetic between file size and pixel layout usually yields a handful of candidate dimensions. We render each candidate and keep the one that resolves into a coherent picture.

Are PBM, PGM and PPM obsolete?

The family is old but far from dead. The netpbm tools, ImageMagick and GIMP all read it today, and its simplicity keeps it popular for test images, teaching examples and quick conversion pipelines.

Should I convert my archive to another format?

For long term storage, yes. A lossless format such as PNG or TIFF holds the same pixels in less space inside a checksummed container. Keep the original only where a workflow still requires it.

If a PBM, PGM or PPM file refuses to open, or opens torn and skewed, our engineers will examine it and tell you plainly what can be recovered. Every repair begins with a free evaluation, and you will know the prospects before any paid work starts.

Send us your .vax 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