What is the PNM File Format?

Portable Anymap is an umbrella name for the Netpbm raster formats PBM, PGM, and PPM. Together they cover monochrome, grayscale, and RGB image data through closely related structures.

How the PNM File Format works

PNM is not a file format of its own: the Netpbm documentation calls it an abstraction that refers collectively to PBM (bi-level), PGM (grayscale), and PPM (color). Each image starts with a two-character magic number, P1 to P6, followed by the width and height as ASCII decimal numbers and, for PGM and PPM, a maximum sample value called maxval. The raw variants (P4, P5, P6) then store the raster in binary, rows top to bottom: PBM packs eight pixels per byte with 1 meaning black, while PGM and PPM use one byte per sample when maxval is below 256 and two bytes, most significant first, otherwise. The plain variants (P1, P2, P3) write every sample as ASCII text. Netpbm describes these formats as intermediaries that, in their purest use, live only in a pipe between two programs.

Key facts

  1. A .pnm name or the image/x-portable-anymap media type does not say which format a file holds. Read the two-character magic number: P1 and P4 are PBM, P2 and P5 are PGM, P3 and P6 are PPM, and the lower number of each pair is the plain text variant. None of the Netpbm media types is registered with IANA. A writer asked for “PNM” has to pick one of the three; ImageMagick, for example, selects the most appropriate one for the image and writes the binary variant unless told otherwise.
  2. PGM and PPM samples are not always 8-bit. The header’s maxval can be any value from 1 to 65535; raw files use one byte per sample when it is below 256 and two bytes, most significant first, otherwise, so 10-bit data with maxval 1023 is valid. Sample values are relative to maxval, so a reader that assumes 255 misreads both the byte layout and the brightness. Netpbm notes that raw files were limited to 255 before April 2000 and that old programs may depend on that.
  3. The three formats have no alpha channel and no field for an ICC profile; the only free-form data is # comments in the header. Netpbm carries transparency as a separate PGM file used as a transparency mask, or in its newer PAM format, where a tuple type such as RGB_ALPHA adds an opacity plane. PAM starts with P7 and is a fourth Netpbm format, not one of the PNM formats, so do not assume a PNM reader accepts it.
  4. A raw PBM, PGM, or PPM file may hold several images back to back with no delimiter, a rule added in July 2000; the plain variants hold exactly one. Netpbm warns that most tools ignore everything after the first image, and OpenImageIO’s documentation lists multi-image as unsupported for PNM, so do not rely on a multi-image file surviving a pipeline.

When the PNM File Format matters

Use PNM-family files as simple intermediates between command-line tools or image-analysis stages, where a parser that fits in a few lines matters more than size. They are uncompressed and carry almost no metadata, so convert to a compressed format for storage or delivery; Netpbm’s own PBM documentation says it is not a format one would normally use to store or transmit a file.

How Transloadit helps with the PNM File Format

Transloadit’s image formats table lists PBM, PGM, PPM, PNM, and PAM as formats its ImageMagick-based Robots, including /image/resize, can read and write, so a Netpbm file can be converted to a compressed format in a Step.

The table reports what each stack can read and write. It does not say which PNM variant is written or how 16-bit samples are handled, and no Assembly was run for this entry.

Explore Transloadit’s file formats & compression capabilities

Sources

Turn media knowledge into a working pipeline

Connect uploads, processing, AI, storage, and delivery through one declarative API — with the encoding stack, scaling, and format churn handled for you.

Try Transloadit for free