# Codec A **codec**, a portmanteau of coder and decoder, is a piece of hardware or software that converts a signal or data stream into a compact coded representation and reverses the process to recover an approximation of the original. The encoding half and the decoding half are built as a matched pair: a stream one encoder produces is only useful if a decoder somewhere agrees on exactly the same rules for undoing it. Some codecs are lossless, reproducing their input exactly; most in everyday use are lossy, accepting a controlled loss of fidelity in exchange for a much smaller stream, following the same trade-off [[Data_compression|data compression]] makes in general. The primary microsim on this page builds a small but genuine transform codec, running the discrete cosine transform, quantization and truncation steps that sit inside formats such as [[MP3]] live in the browser, and reconstructing the result so the cost of each choice can be seen directly. ## History The term arose in telephony, describing a device built to convert one analog voice line into a digitized stream and back again, work that rests on the [[Pulse-code_modulation|pulse-code modulation]] techniques used to represent an analog waveform as a sequence of numbers in the first place. Those early telephony codecs already made a lossy choice long before transform coding existed: rather than spacing quantization steps evenly across the full voltage range, they compressed loud signals into coarser steps and left quiet ones finely spaced, a technique called [[Companding|companding]], because a listener's ear tolerates coarse quantization far better on a loud signal than on a quiet one. Media codecs in the modern sense became possible once transform coding gave a practical way to compress a natural signal with an acceptable loss of quality: Nasir Ahmed, T. Natarajan and K. R. Rao published the discrete cosine transform in 1974, showing it approximated the statistically optimal transform for compressing typical images and audio far more cheaply than that optimal transform could be computed[^dct1974]. Standardisation followed over the next three decades: the JPEG still-image codec was completed in 1992[^jpeg92], the MPEG-1 standard defined codecs for digital audio and video in 1993[^mpeg1a][^mpeg1v], and H.264, still the most widely deployed video codec family, was standardised jointly by the ITU and MPEG in 2003[^h264]. Each generation kept the same core structure while improving the prediction and entropy-coding stages built around it. ## Examples A codec is usually named for the compression scheme it implements rather than for any particular product: [[MP3]] is a codec for compressed audio, and dozens of others cover speech at very low bit rates through dedicated [[Speech_coding|speech coding]] techniques, general-purpose music and effects audio, still images, and video. It is worth keeping the codec itself distinct from the file or stream format that carries it: a format is a container that wraps coded data with metadata such as timing and stream identification, and the same container can in principle hold output from more than one codec, while the same codec's output can be wrapped in more than one container. A device or program that only encodes, or only decodes, is sometimes called simply a coder or a decoder; a device built to do both toward a single line, historically the case in telephony equipment, is occasionally called an endec instead, though the distinction is rarely enforced strictly in practice. ## Compression Most media codecs are built around the same three-stage pipeline the primary sketch on this page runs directly on a test signal: a transform repacks the signal so that most of its energy concentrates in a few coefficients, a quantizer rounds each coefficient to the nearest multiple of a step size and discards everything finer, and an entropy coder packs the surviving, now highly skewed, distribution of values into as few bits as their statistics allow. The transform step is typically the [[Discrete_cosine_transform|discrete cosine transform]] Ahmed, Natarajan and Rao introduced in 1974 precisely because natural images and audio compact so well under it[^dct1974]; the [[Quantization_(signal_processing)|quantization]] step is the only one that loses information outright, and it loses a predictable amount, since representing a quantity with one additional bit of resolution lowers the mean-squared quantization error by about 6.02 dB, a relationship that holds whether the quantity being quantized is a raw sample or a transform coefficient[^b014quant]. A concrete case makes the size of these steps tangible: representing a signal spanning 0 to 5 volts with only 3 bits gives a step of 0.625 volts, so a true value of 2.36 volts is reported as 2.5 volts, an error of nearly 6 percent, while the same range at 8 bits steps in about 0.02-volt increments and cuts that worst-case error by more than an order of magnitude[^b014ex22]. Every codec built this way answers the same question the sketch poses with its own quantization-step and coefficient-count controls: given a fixed budget, which of the transform's coefficients earn their bits and which can be rounded away or dropped outright. ## Media codecs Media codecs split naturally by the kind of signal they carry. Audio codecs range from speech coders, which model how a human vocal tract produces sound and can reach very low bit rates by transmitting only that model's parameters, to general-purpose audio codecs, which instead model how a human ear perceives whatever sound is playing and allocate bits accordingly regardless of its source. Image and video codecs almost all use a block-based transform, most often the discrete cosine transform the primary sketch implements, though some use a [[Discrete_wavelet_transform|discrete wavelet transform]] instead, applied across an entire image rather than block by block; video adds a further, temporal dimension by predicting each frame from a previous one and coding only the difference, so that a video codec is, in effect, a still-image codec with a motion-prediction stage bolted on the front of it. Because the transform-quantize-entropy pipeline is common to nearly all of them, most media codecs differ from one another mainly in the details of prediction, block size and entropy coding layered around that shared core, rather than in the basic strategy. ## Malware A codec's decoder is software that parses data from an untrusted source, often written for speed in a memory-unsafe language, which makes it a long-standing target for attackers: a media file crafted to trigger a parsing bug in a vulnerable decoder can potentially run arbitrary code on whatever device opens it, a risk shared with any [[Computer_science|software]] that parses complex, attacker-supplied input. Codecs have also been a favoured disguise for [[Software_engineering|malware]] distributed through social engineering rather than a parsing exploit: one well-documented example, the Zlob trojan, first identified in 2005, spread for years by presenting itself as a codec a video player supposedly needed before it could play a downloaded file, tricking users into installing it directly[^zlob]. A related but distinct risk came from codec packs, bundles bought together on the promise of playing every format a user might encounter: because such a pack silently installed many decoders from many sources at once, an infected or badly maintained one could compromise the whole bundle, which is one reason media players increasingly ship their own vetted decoders rather than relying on whatever the operating system happens to have installed. Modern operating systems and browsers respond to both risks by running codec decoders in sandboxed processes with reduced privileges and by pushing codec updates through the same channel as other security patches, rather than leaving media playback dependent on whatever decoder a user happened to install from an untrusted source. ## Microsims The only sketch on this page, **Codec**, runs a real, small transform codec: it encodes a scrolling test signal with a discrete cosine transform, quantizes and truncates the coefficients, then decodes the result and measures what was lost. *Quant step Q* sets how coarsely coefficients are rounded; *Keep K* sets how many low-frequency coefficients survive before the rest are discarded; *Signal detail* narrows or widens a pulse in the test signal, adding or removing high-frequency content for the codec to work with. Watch the estimated coded size, the compression ratio against raw pulse-code-modulated storage, and the reconstruction signal-to-noise ratio update together as each control moves. *Try:* Hold the compression ratio roughly constant by trading quant step against kept coefficients — coarsen Q while raising K, then tighten Q while lowering K — and compare the reconstruction SNR the sketch reports for each path to the same bit budget. ## Wikipedia : Wikitube **Strict pair:** [Wikipedia](https://en.wikipedia.org/wiki/Codec) : [Wikitube](https://en.wikitube.io/wiki/Codec) Skeleton mirrored at revision 1371316998. Prose, emphasis and the microsims are Wikitube's own. ## See also - [[MP3]] - [[Pulse-code_modulation]] - [[Data_compression]] - [[Discrete_cosine_transform]] - [[Speech_coding]] ## References [^dct1974]: Ahmed, N.; Natarajan, T.; Rao, K. R. "Discrete Cosine Transform." *IEEE Transactions on Computers*, vol. C-23, no. 1, 1974, pp. 90–93. https://doi.org/10.1109/T-C.1974.223784 . [^jpeg92]: ITU-T Recommendation T.81, *Information Technology — Digital Compression and Coding of Continuous-Tone Still Images — Requirements and Guidelines*. International Telecommunication Union, September 1992. https://www.w3.org/Graphics/JPEG/itu-t81.pdf . [^mpeg1a]: ISO/IEC 11172-3:1993, *Information technology — Coding of moving pictures and associated audio for digital storage media at up to about 1.5 Mbit/s — Part 3: Audio*. International Organization for Standardization, 1993-08-01. https://www.iso.org/standard/22412.html . [^mpeg1v]: ISO/IEC 11172-2:1993, *Information technology — Coding of moving pictures and associated audio for digital storage media at up to about 1.5 Mbit/s — Part 2: Video*. International Organization for Standardization, 1993. https://www.iso.org/standard/22411.html . [^h264]: ITU-T Recommendation H.264, *Advanced Video Coding for Generic Audiovisual Services*. International Telecommunication Union, May 2003. https://www.itu.int/rec/T-REC-H.264 . [^zlob]: Huntress Labs. "Zlob." *Huntress Threat Library*. https://www.huntress.com/threat-library/malware/zlob (retrieved 2026). [^b014quant]: Dyer, J.; Davis, C. *Measurement and Instrumentation: An Introduction to Concepts and Methods*, 1st ed. 2020, pp. 39–40 (PDF pages). Open Textbook Library: https://open.umn.edu/opentextbooks/textbooks/measurement-and-instrumentation-an-introduction-to-concepts-and-methods . CC BY-NC-SA. [^b014ex22]: Dyer, J.; Davis, C. *Measurement and Instrumentation: An Introduction to Concepts and Methods*, 1st ed. 2020, pp. 33–34 (PDF pages). Open Textbook Library: https://open.umn.edu/opentextbooks/textbooks/measurement-and-instrumentation-an-introduction-to-concepts-and-methods . CC BY-NC-SA. <!-- Hubs: Signal_processing. Portals: PORTAL_Signal_Processing. Signal Processing portal wave 1 · 2026-09-17 · drafted. -->