What is the PNM file format?
.pnm (Portable Anymap) is an umbrella extension covering three related uncompressed raster image sub-formats from the Netpbm family: PBM (Portable Bitmap, 1-bit black-and-white), PGM (Portable Graymap, greyscale), and PPM (Portable Pixmap, colour). The actual sub-type of any .pnm file is identified by its first two bytes: P1-P3 for the ASCII ("plain") variants and P4-P6 for the binary ("raw") variants.
Jef Poskanzer created the original PBM format in 1988 as part of his Pbmplus toolkit, adding PGM and PPM shortly after. The formats were designed to be the simplest possible lossless image representation, capable of surviving transit over 7-bit email links. The ASCII variants store pixel values as whitespace-separated decimal integers after a plain-text header; the binary variants pack raw bytes immediately after the header for more compact storage.
Color depth ranges from 1 bpp (PBM) to 16 bpp per channel (PGM/PPM with 16-bit maxval), yielding up to 48 bpp for colour images. The format defines no compression, encryption, colour profile, EXIF data, or thumbnails - it is deliberately minimal.
PNG is the modern replacement for lossless storage, but .pnm files remain a ubiquitous intermediate format in Unix image-processing pipelines. ImageMagick, GIMP, FFmpeg, and virtually all Unix image tools read and write the format natively.
Security & safety
RISK: LOWPNM/PBM/PGM/PPM are among the simplest image formats - plain text header plus raw pixel data (or ASCII values). No code execution, no scripting, no compression exploits. Very safe to open. The main risk is the trivially large uncompressed file size for high- resolution images.
Format details
in a nutshellPrograms that open PNM files
Technical details
deep spec| Sub-formats | Umbrella for PBM (P1/P4, 1-bit), PGM (P2/P5, greyscale), and PPM (P3/P6, colour) |
| Magic bytes | First 2 bytes: `P` (0x50) + digit `1`-`6` (0x31-0x36) - identifies sub-type and ASCII vs. binary encoding |
| ASCII variants (P1-P3) | Pixel values stored as whitespace-separated decimal integers - human-readable and 7-bit safe |
| Binary variants (P4-P6) | Raw pixel bytes packed immediately after the ASCII header - more compact, same logical data |
| Compression | None - pixel data stored uncompressed in all variants |
| Color depth | 1 bpp (PBM); 8 or 16 bpp per channel greyscale (PGM); 24 or 48 bpp colour (PPM with 16-bit maxval) |
| Header structure | ASCII fields: magic number, optional `#` comment lines, width, height, then maxval (absent for P1/P4 1-bit) |
| Byte order | Big-endian for 16-bit samples in binary P5/P6 variants; not applicable for 8-bit or ASCII formats |
| Maxval constraint | Must be 1-65,535 (uint16); values ≤ 255 use 1 byte per sample in binary P4-P6 modes |
| Dimensions | No defined maximum; limited in practice by available system memory |
| MIME type | `image/x-portable-anymap`; sub-types: `image/x-portable-bitmap`, `image/x-portable-graymap`, `image/x-portable-pixmap` |
| PAM extension | P7 (`.pam`, Portable Arbitrary Map) extends PNM to arbitrary channel counts and bit depths |
| Typical use | Unix image-processing pipeline intermediate format; native I/O for ImageMagick, GIMP, FFmpeg, and most Unix image tools |
| Released | 1988 (Jef Poskanzer's Pbmplus toolkit; PBM first, PGM and PPM by year-end) |
| Latest version | Netpbm 11.x (2020s); format spec stable since early 1990s |
| Open standard | Yes · royalty-free |
| Specification | netpbm.sourceforge.net |
PNM conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about PNM files.