Image format

PGM

Portable Graymap: simple uncompressed raster samples for image-processing pipelines.

Explore the format

Convert PGM to

Choose a target format for your PGM images.

All 21 conversions

Marked paths may need steps such as flattening, rasterization, tone mapping or animation loss.

Convert to PGM

Choose a source format to convert to PGM.

All 36 conversions

Marked paths may need steps such as flattening, rasterization, tone mapping or animation loss.

About PGM

Portable Graymap

PGM is Netpbm’s simple grayscale raster format. It stores one intensity sample per pixel instead of RGB components. A header declares width, height and maximum sample value. This makes grayscale images easy to exchange between small programs without needing a palette or a general-purpose colour container.

P2 represents samples as text; P5 uses binary samples, one or two bytes according to maxval, up to 65535. Data is uncompressed and there is no separate alpha channel. The manual also describes an opacity-mask variant; a grayscale image and a mask can use the same storage but have different meanings.

Use PGM for grayscale processing and explicit single-channel masks. Document whether samples represent intensity, opacity or application data. Colour conversion to PGM removes chromatic information and requires a chosen grayscale mapping; increasing the sample precision later cannot recover removed colours or tonal values.

Key capabilities

Compression
Uncompressed
Transparency
No
Animation
No
Extensions
.pgm
MIME type
image/x-portable-graymap · Unregistered Netpbm convention
Metadata
Header, Comments
Best for
Grayscale images & masks
Colour depth
maxval up to 65535

Netpbm stores these samples without compression. Reducing colour, thresholding or changing maxval can still lose information before storage; text and binary representations change the layout, not its image meaning.

History of PGM

This format belongs to the documented Pbmplus/Netpbm evolution. The history distinguishes the original bitmap idea, later channel models and library development.

  1. 1980s

    A simple interchange language

    Jef Poskanzer invents PBM to exchange bitmaps using a representation simple enough for text-only email. Its aim is robust interchange between otherwise incompatible graphics tools.

  2. 1988

    Pbmplus and colour formats

    Poskanzer distributes Pbmplus in 1988 and adds PGM and PPM by the end of that year. The toolkit extends the original bitmap exchange to grayscale and RGB images.

  3. 1993

    Netpbm replaces Pbmplus

    Netpbm begins as a new release of the unmaintained Pbmplus package, with fixes and improvements contributed over the network. The format family remains a bridge among graphics tools.

  4. 2000-04

    Two-byte samples

    The maintained Netpbm distribution documents two-byte samples up to a maxval of 65535 and a defined byte order for PGM and PPM. This resolves ambiguity between earlier extensions.

PGM compared

Different formats, different trade-offs. Choose for the image and the workflow.

PPM

PGM vs PPM

PPM stores three RGB samples per pixel without compression or alpha. It is easy to inspect in processing pipelines, but sacrifices compactness and rich metadata; select it when direct sample interchange is the priority.

PBM

PGM vs PBM

PBM stores only black and white, one bit per pixel in its binary form. It fits bitonal masks and line art; tonal images need thresholding or dithering, so gradients cannot remain as continuous gray levels.

PAM

PGM vs PAM

PAM extends Netpbm with explicit tuple types and depths, including RGB_ALPHA and GRAYSCALE_ALPHA. It suits channel-aware processing, but receiving tools must agree on the tuple meaning and it remains uncompressed.

PNG

PGM vs PNG

PNG preserves decoded pixels losslessly and can carry alpha. It is useful for transparent graphics and screenshots; it does not preserve editable document layers or camera sensor data, and photographic files can be large.

PGM FAQ

What does this format store?

PGM is Netpbm’s simple grayscale raster format. It stores one intensity sample per pixel instead of RGB components. A header declares width, height and maximum sample value. This makes grayscale images easy to exchange between small programs without needing a palette or a general-purpose colour container.

How does compression affect quality?

Netpbm stores these samples without compression. Reducing colour, thresholding or changing maxval can still lose information before storage; text and binary representations change the layout, not its image meaning.

Is a PGM mask an alpha channel?

It can be interpreted as an opacity mask by agreement, but the file contains only one channel. It does not combine grayscale image pixels with a separate alpha channel as PAM GRAYSCALE_ALPHA can.

What should I check before opening the file?

Check the magic number, sample precision and tuple or channel meaning. Many simple readers accept only one binary image and 8-bit samples even though the specifications permit more.

What changes when I export to another format?

Preserve maxval and colour interpretation when creating the rendered output. Grayscale and bitonal targets remove information deliberately; alpha requires an alpha-bearing tuple or a separate mask. Optional comments may not transfer.

When is this format useful?

Use PGM for grayscale processing and explicit single-channel masks. Document whether samples represent intensity, opacity or application data. Colour conversion to PGM removes chromatic information and requires a chosen grayscale mapping; increasing the sample precision later cannot recover removed colours or tonal values.

Sources