A codec is a coder-decoder: the matched pair of algorithms that compresses media into a compact coded representation (the coder, or encoder) and reconstructs it for playback or display (the decoder). The word is a portmanteau of “coder” and “decoder,” and the concept sits at the heart of nearly all digital audio, image, and video. Raw media is enormous: a few seconds of uncompressed CD-quality audio or a single uncompressed photograph can be megabytes, and uncompressed video is impractical to store or transmit at scale. Codecs make digital media usable by trading computation for size.
Codecs divide broadly into lossless and lossy. A lossless codec guarantees that the decoded output is bit-for-bit identical to the input; it removes only statistical redundancy. PNG, specified in RFC 2083, is a lossless image codec, and its DEFLATE-based compression always reconstructs the exact original pixels. A lossy codec, by contrast, deliberately discards information judged imperceptible or unimportant in order to achieve much higher compression. JPEG, specified in ITU-T Recommendation T.81, is a lossy image codec: its DCT-and-quantization pipeline throws away high-frequency detail the eye is least likely to notice, and the decoded image is only an approximation of the original.
Lossy codecs for audio and video typically rely on perceptual models and prediction. Audio codecs such as MP3 use psychoacoustic models to remove sound the ear cannot hear. Video codecs such as those in the MPEG family and H.264 combine spatial transform coding within a frame with motion-compensated prediction between frames, so that most of a moving picture is coded as differences from reference frames rather than from scratch. In every case the standard usually defines the bitstream syntax and the decoding process precisely while leaving encoder design open, which lets many encoders of differing speed and quality all produce streams a single conforming decoder can read.
A crucial and frequently confused distinction is between a codec and a container. The codec defines how the media samples themselves are compressed; the container, or wrapper format, defines how one or more coded streams are packaged together with metadata, timing, and synchronization information into a file or transport stream. JPEG’s coded data is wrapped in JFIF or Exif files; H.264 video is commonly carried in MP4, Matroska, or an MPEG transport stream alongside an audio codec such as AAC. The same codec can appear in many containers, and the same container can hold many different codecs, which is why a file extension alone does not determine whether a given player can decode the contents.
The codec concept is therefore a layered one: foundational compression techniques (entropy coding, transform coding, prediction, quantization) are combined into specific standardized codecs, those codecs produce coded streams, and containers assemble the streams into deliverable media. Understanding this layering explains much of the practical landscape of digital media, from why a video might play its picture but not its sound, to why the same song can be a small lossy file or a large lossless one, to why patent disputes over a single compression algorithm can ripple across an entire generation of file formats.