UTF-8
Unicode Consortium-aligned encoding standard
UTF-8 is a variable-width character encoding that represents every Unicode code point using one to four bytes, designed to be backward compatible with 7-bit ASCII while efficiently encoding the full range of the world's writing systems in…
Definition
UTF-8 is a variable-width character encoding that represents every Unicode code point using one to four bytes, designed to be backward compatible with 7-bit ASCII while efficiently encoding the full range of the world's writing systems in one shared scheme. It is the dominant text encoding on the web and across most modern software, databases, and operating systems in use today.
Overview
Before a unified encoding standard, different regions and systems used incompatible character encodings to represent text beyond basic English, making it unreliable to exchange documents across languages or software platforms without corruption or misinterpretation of individual characters. Unicode addressed the underlying problem by assigning every character across virtually all writing systems a unique code point, but Unicode itself does not dictate how those code points are stored as bytes on disk or transmitted over a network — that specific role is what UTF-8 fills. UTF-8 encodes each Unicode code point using between one and four bytes, with the number of bytes determined by leading bit patterns that let software unambiguously identify where each character starts and ends without needing to track byte order separately from the data itself. Critically, the first 128 Unicode code points, which correspond exactly to ASCII, are encoded identically to standard ASCII as single bytes, meaning any valid ASCII text is automatically valid UTF-8 text, which greatly eased adoption because existing ASCII-based systems and stored files did not need any conversion to become UTF-8 compliant. Among Unicode encodings, UTF-8 differs from UTF-16 and UTF-32 primarily in byte efficiency for common cases and endianness handling: UTF-16 uses two or four bytes per character and requires specifying byte order, while UTF-32 uses a fixed four bytes per character regardless of complexity, trading space efficiency for simpler fixed-width indexing capability across strings. UTF-8's compactness for Latin-script text and its ASCII compatibility are the main reasons it displaced competing encodings for web and file-format use over time. In practice, UTF-8 is the default or required encoding for HTML, JSON, and most modern programming language source files and native string types, and it is the encoding assumed by default across the overwhelming majority of web content and internet protocols in use today. Choosing UTF-8 for new software is generally treated as the safe default rather than a decision requiring justification or debate. UTF-8's variable-width nature does introduce trade-offs: indexing into a UTF-8 string by character position is not a constant-time operation the way it is with fixed-width UTF-32, since a program must scan bytes to find character boundaries, and text using many non-Latin characters can require more bytes per character than a fixed-width encoding tuned to that script would need. These costs are generally considered acceptable given UTF-8's compatibility and near-universal adoption across the industry and internet infrastructure at large scale.
Specification
- Variable-width encoding using one to four bytes per code point
- Fully backward compatible with 7-bit ASCII text
- Encodes the entire Unicode character range without byte-order marks
- Default or required encoding for HTML and JSON
- More space-efficient than UTF-32 for Latin-script text
- Near-universal adoption across web content and internet protocols