How JPEG, PNG, WebP and GIF store metadata (and how lossless removal works)

By ExifZero Engineering · Updated

Short answer: Image formats do not mix metadata into pixel bytes. JPEG wraps metadata in APP1–APP15 and COM marker segments, PNG uses named chunks such as eXIf, tEXt, iTXt and caBX, WebP uses RIFF chunks paired with header bitflags in VP8X, and GIF uses extension blocks (0x21 0xFE and 0x21 0xFF). Cutting out those non-image blocks and updating container headers leaves the compressed pixel stream byte-for-byte unchanged.

A common misconception about metadata removers is that every cleaner has to open the picture, redraw it onto an invisible canvas, and save a brand new file. Canvas re-saving works, but it throws away compression quality on JPEGs, bloats lossless graphics, and frequently discards the ICC color profile. Knowing how the underlying file containers are laid out makes it obvious why direct block editing is both faster and cleaner.

Visual layout: JPEG segments vs. PNG chunks

Inside a JPEG or PNG, image pixels and metadata sit in consecutive, self-delimiting blocks. A container-level stripper walks each block's length prefix, copies the blocks needed to decode colors and pixels, and skips the rest.

JPEG byte stream (markers 0xFFxx) SOI Keep APP1 EXIF Strip APP1 XMP Strip APP2 ICC Keep opt. APP11 C2PA Strip DQT/SOF/SOS/EOI Keep byte-for-byte Trailer MP4 Strip PNG chunk sequence (length + 4-byte type + data + CRC-32) Sig + IHDR Keep iCCP Keep opt. tEXt / iTXt Prompts / XMP eXIf / caBX Strip IDAT ... IDAT Keep byte-for-byte IEND Keep
Both JPEG and PNG isolate image decoding blocks from metadata blocks, allowing a parser to slice out metadata without touching compressed pixel streams.

1. JPEG marker segments

A JPEG file begins with Start of Image (0xFFD8, SOI) and runs through variable-length marker segments until End of Image (0xFFD9, EOI). Each metadata segment starts with a 2-byte marker followed by a 2-byte big-endian length:

If any bytes exist after EOI, decoders ignore them, yet file scanners and ExifZero's File structure tab flag them as a trailer block — catching Android Motion Photos (an MP4 clip appended after EOI) and hidden payloads.

Real before/after block map (JPEG)

Open any photo in ExifZero and switch to the File structure tab to read this table live. On a typical phone or AI-tagged JPEG, cleaning shrinks the block list to the bare decoding skeleton:

BEFORE CLEANING (1,428,912 bytes)
  0 .. 2         SOI    Image data
  2 .. 20        APP0   JFIF header (Image structure)
  20 .. 16840    APP1   EXIF (GPS, device serial, IFD1 thumbnail)  -> DROP
  16840 .. 21104 APP1   XMP (creator, history, DigitalSourceType) -> DROP
  21104 .. 24260 APP2   ICC color profile                         -> KEEP (optional)
  24260 .. 89412 APP11  JUMBF (C2PA Content Credentials)          -> DROP
  89412 .. 1428910 DQT/DHT/SOF0/SOS/EOI (compressed pixel scan)   -> KEEP

AFTER CLEANING (1,340,180 bytes — 88,732 bytes removed, 0 pixels altered)
  0 .. 2         SOI    Image data
  2 .. 20        APP0   JFIF header
  20 .. 52       APP1   Minimal EXIF (Orientation = 6 only, if rotated)
  52 .. 3208     APP2   ICC color profile
  3208 .. 1340180 DQT/DHT/SOF0/SOS/EOI (identical scan bytes)

2. PNG chunks and CRC-32 checksums

PNG files start with an 8-byte signature followed by four-part chunks: a 4-byte length, a 4-character ASCII type, the payload, and a 4-byte CRC-32 checksum covering the type and payload. The case of the first letter tells decoders whether a chunk is critical (IHDR, PLTE, IDAT, IEND) or ancillary.

Metadata hides in ancillary chunks: tEXt (uncompressed Latin-1), zTXt (zlib-compressed), and iTXt (UTF-8, optionally compressed — used by Adobe XMP under key XML:com.adobe.xmp and by ComfyUI/A1111 for prompts). Modern PNGs also carry eXIf for binary EXIF, tIME for modification timestamps, and caBX for C2PA manifests. Color-rendering chunks such as sRGB, gAMA, cHRM, cICP and iCCP control how colors map to your monitor and contain no personal data. When preserving rotation on a PNG, any new minimal eXIf chunk inserted right after IHDR must calculate an exact CRC-32 trailer or strict PNG decoders will reject the file.

3. WebP RIFF chunks and the VP8X header pitfall

WebP wraps image and metadata inside a Little-Endian RIFF container: 12-byte header (RIFF + total file size minus 8 + WEBP) followed by padded chunks. Image data sits in VP8 (lossy), VP8L (lossless), or animation frames (ANIM, ANMF). Metadata sits in EXIF, XMP , and C2PA, with color profiles in ICCP.

Here is the trap that breaks naive WebP cleaners: whenever a WebP carries ICC, EXIF, XMP, alpha or animation, its first chunk is an extended header named VP8X containing bitflags (0x20 for ICC, 0x08 for EXIF, 0x04 for XMP). If a script deletes the EXIF or XMP chunk without clearing those bits in VP8X — and without rewriting the 32-bit RIFF size at byte offset 4 — Chrome, macOS Preview and libwebp can treat the file as corrupt.

4. GIF extensions

GIF87a and GIF89a store headers, color tables, frame descriptors and LZW-compressed frames, alongside extension blocks introduced by 0x21. Label 0xFE stores plain-text comments (where some generators write tool strings), while label 0xFF (Application Extension) handles both animation looping (NETSCAPE2.0) and Adobe XMP (XMP DataXMP) or ICC profiles (ICCRGBG1012). Dropping 0xFE and XMP DataXMP while preserving loop extensions leaves animated GIFs fully playable.

Lossless block stripping vs. canvas re-encoding

PropertyLossless block strippingBrowser canvas re-encode
Pixel valuesBit-for-bit identicalRecompressed (generation loss on JPEG)
ICC color profileKept optionally without converting pixelsTypically stripped or clipped to sRGB
Animation (GIF / WebP)Preserved across all framesCollapsed to a single static frame
File sizeShrinks strictly by removed metadata bytesCan double or triple on clean PNGs/JPEGs
Supported formatsJPEG, PNG, WebP, GIFNeeded for HEIC, AVIF, TIFF (no native JS muxer)

Frequently asked questions

Why does removing EXIF with ExifZero keep image quality 100% identical?

Because JPEG, PNG, WebP and GIF store metadata in separate labelled segments or chunks outside the compressed pixel stream. ExifZero copies the image-data blocks byte for byte and omits the metadata blocks, so pixels are never decoded or recompressed.

Why does a cleaned JPEG still have a small APP1 segment when Keep rotation is checked?

Phone cameras often store pixels sideways and rely on an EXIF Orientation tag (1 through 8) to tell viewers which way is up. When Keep rotation is enabled and orientation is greater than 1, ExifZero writes a fresh, minimal 1-tag TIFF/EXIF block containing only that orientation integer — zero camera, date or GPS tags.

Why can’t ExifZero strip HEIC or AVIF without re-encoding?

HEIC and AVIF use complex ISO Base Media File Format (ISOBMFF) box trees with item property tables and offsets. Browsers can decode them via native OS codecs onto a canvas, so ExifZero converts them to a clean high-quality JPEG and labels them “re-encoded” in the interface.

What is “Data after image end” in the File structure tab?

Some cameras and Android phones append extra data — most commonly an MP4 Motion Photo clip — after the JPEG End of Image marker (0xFFD9) or PNG IEND chunk. Image decoders stop at the end marker, so that hidden trailer often goes unnoticed until a container scanner reads the full byte length.

Related tools

Related guides

Browse all 16 guides →