Guides Design & Media

How Image Formats and Compression Work

JPEG, PNG, GIF, WebP, AVIF, HEIC and SVG compared with measured file sizes, lossy versus lossless, aspect ratio and print maths, and which tool to use.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

A digital image is a grid of pixels, and an image file is a way of storing that grid in fewer bytes. The format you pick decides how many bytes, whether detail is lost and whether you get transparency. This guide explains the trade-offs with measured numbers, and which tool to reach for.

Pixels, size and the file you start from

An uncompressed pixel takes 3 bytes (red, green, blue). A 4000 × 3000 phone photo is 12 megapixels, which is 36,000,000 bytes, about 34.3 MiB, before compression. Formats shrink that by finding patterns, which is why photos usually arrive as files of a few megabytes.

Aspect ratio is width divided by height, simplified. 1920 × 1080 reduces by 120 to 16:9 and 4000 × 3000 to 4:3. To resize without distortion, change one side and compute the other: a 16:9 image 800 wide is 450 tall. The Aspect Ratio Resizer and Image Resizer keep the ratio, the Bulk Image Resizer handles many files and the Image Dimension Inspector reads the size of an existing one.

Print size is pixels divided by pixels per inch: a 6 × 4 inch print at 300 ppi needs 1800 × 1200 pixels. A screen image has no inherent size; only its pixels matter.

Lossy versus lossless

  • Lossless formats (PNG, GIF, lossless WebP) store every pixel exactly. Decoding returns the original.
  • Lossy formats (JPEG, lossy WebP, AVIF, HEIC) discard detail the eye is least likely to miss, so files are far smaller but cannot be restored. A quality setting trades size for fidelity.

The formats compared

Format Compression Transparency Animation Best for
JPEG Lossy No No Photographs
PNG Lossless Yes Rarely (APNG) Screenshots, logos, graphics with text
GIF Lossless, 256 colours 1-bit Yes Short simple animations
WebP Both Yes Yes Web images of any kind, smaller than JPEG or PNG
AVIF Both Yes Yes The smallest files at a given quality, HDR; slower to encode
HEIC / HEIF Lossy Yes Yes Phone photos (iPhone default); poor browser support
SVG Vector (no pixels) Yes Via CSS or SMIL Icons, logos and diagrams at any size

Lossy compression suits natural, noisy images such as photographs. Lossless compression suits flat colours and sharp edges. We measured the same two synthetic 800 × 600 test images, each 1,440,000 bytes uncompressed:

Format Graphic (flat colours, sharp edges) Photo-like (smooth with texture)
PNG 7,203 bytes 722,265 bytes
JPEG, quality 85 45,938 bytes 70,979 bytes
JPEG, quality 50 26,980 bytes
WebP lossless / lossy 80 2,780 bytes 30,498 bytes
AVIF, quality 60 4,180 bytes 31,491 bytes

On the flat graphic, PNG is about 6 times smaller than JPEG, and JPEG would also smear the sharp edges. On the photo-like image the situation reverses: JPEG at quality 85 is about 10 times smaller than PNG, and WebP and AVIF at similar quality are smaller still. Your own files will differ, but the pattern holds.

Converting between formats

Use the converter that matches your starting point: JPG to PNG Converter, PNG to JPG Converter, JPG to WebP Converter, PNG to WebP Converter, WebP to JPG Converter, WebP to PNG Converter, HEIC to JPG Converter, AVIF to JPG Converter and SVG to PNG Converter. Converting to a lossy format always loses detail, and converting lossy to lossless does not bring it back, it just makes a bigger file. Collect photos into a document with the Image to PDF Converter and pull pages back out with the PDF to Image Converter.

To embed a small image directly in HTML or CSS, encode it with the Image to Base64 Converter (and reverse it with the Base64 to Image Converter). Base64 turns every 3 bytes into 4 characters, so the data is 33.3% larger; reserve it for tiny icons.

Editing without wasting quality

Every save as JPEG recompresses, so do all your edits first and export once. Keep an original. Tools that change pixels: Image Cropper, Image Rotator, Image Flipper, Image Splitter, Image Collage Maker, Image Watermark Adder and Profile Picture Maker. Reduce file size with the Image Compressor. Visual effects: Image Blur Tool, Image Brightness & Contrast Adjuster, Image Grayscale Converter, Image Pixelator and the Image to ASCII Art Converter.

Special cases

Common mistakes

  • Saving a screenshot as JPEG. Text gets fuzzy halos and the file is larger; use PNG or lossless WebP.
  • Saving a photo as PNG. The file is many times larger than it needs to be.
  • Upscaling a small image. It adds pixels, not detail.
  • Ignoring metadata. Photos can carry location data; see How EXIF Photo Metadata Works.

Try these tools

See also

  • Guide How EXIF Photo Metadata Works
    What EXIF stores inside a photo, where it sits in a JPEG, how to turn GPS degrees into decimal coordinates.
  • Guide How Color and Contrast Work
    Hex, RGB and HSL are one colour, how the WCAG contrast ratio is computed with real pass and fail examples.
  • Glossary JPEG
    JPEG is a lossy image format designed for photographs that makes small files by discarding detail the eye is least likely to notice.
  • Glossary PNG
    PNG is a lossless image format with transparency, well suited to screenshots, logos and graphics with text or flat colours.
  • Glossary WebP
    WebP is a modern image format from Google that supports lossy and lossless compression.
  • Glossary Aspect ratio
    Aspect ratio is the proportion of an image or screen's width to its height, written as two numbers such as 16:9.

Frequently Asked Questions

WebP is a good default for both photos and graphics, with JPEG or PNG as a fallback. Use AVIF where you want the smallest files, and SVG for logos and icons.

AdSense Placeholder
Slot: footer_leaderboard