# Encoding basics

Canonical URL: https://encode.wiki/start-here/encoding-basics/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): 4293c28f3e72c96d46294d81e489389f9444c552d1b3dc867430c9fc8e66941f

Media compression is what makes streaming video, music libraries and photo-heavy web pages practical. Uncompressed 1080p video at 24 frames per second in 8-bit 4:2:0 takes roughly 600 Mbit/s; a good AV1 or HEVC encode of the same film looks almost identical at a few Mbit/s. This wiki explains how that works and how to get good results with the tools people actually use.

## What is a codec

A **codec** (coder/decoder) is a way of representing media in compressed form, defined by a specification. H.264, AV1 and Opus are codecs. It helps to keep three things apart:

- The **format** is the standard itself: what a valid compressed stream looks like and how to decode it.
- An **encoder** is a program that produces such a stream. One format can have many encoders of very different quality and speed: for AV1 there are [SVT-AV1](/tools/software-encoders/svt-av1/), [aomenc](/tools/software-encoders/aomenc/), [rav1e](/tools/software-encoders/rav1e/) and hardware encoders in GPUs.
- A **decoder** turns the stream back into pictures or sound. For modern video codecs every conforming decoder produces bit-identical pictures from the same stream, so picture quality is decided at encode time.

Most media codecs are **lossy**: they throw away information you are unlikely to notice in exchange for much smaller files (see [lossy compression](/start-here/lossy/)). **Lossless** codecs reconstruct the input exactly and compress far less (see [lossless compression](/start-here/lossless/)).

Codecs exist for each kind of media:

- **Video**: [H.264](/codecs/video/avc/), [HEVC](/codecs/video/hevc/), [VP9](/codecs/video/vp9/), [AV1](/codecs/video/av1/), and lossless formats such as [FFV1](/codecs/video/ffv1/).
- **Audio**: [Opus](/codecs/audio/opus/), [AAC](/codecs/audio/aac/), [MP3](/codecs/audio/mp3/), and lossless [FLAC](/codecs/audio/flac/).
- **Images**: [JPEG](/codecs/images/jpeg/), [PNG](/codecs/images/png/), [WebP](/codecs/images/webp/), [AVIF](/codecs/images/avif/) and [JPEG XL](/codecs/images/jxl/). Image formats also have to handle bit depth, transparency, color profiles, HDR and metadata such as EXIF.
- **General data**: [ZIP](/codecs/data/zip/), [zstd](/codecs/data/zstd/) and similar compressors work on any data, not just media.

## Containers

A video file is usually a **container** holding several compressed streams: video, one or more audio tracks, subtitles, chapters and metadata. [Matroska (MKV)](/containers/matroska/), [MP4](/containers/mp4/) and [WebM](/containers/webm/) are containers, not codecs. Changing the container (**remuxing**) copies the streams without re-encoding them; changing the codec (**transcoding**) decodes and re-encodes, which for lossy codecs always costs some quality.

The [terminology](/start-here/terminology/) page defines these and other terms in more detail.
