UTF-8
| Standard | |
|---|---|
![]() Image placeholderPlace the file shown below in the assets/articles folder utf-8.webp | |
| Defined in | RFC 3629 |
| Designed by | Ken Thompson, Rob Pike |
| Year | 1992 |
| Width | 1 to 4 bytes |
UTF-8 is an encoding of Unicode. It is defined in RFC 3629 and is the most widely used text encoding on the web.
Problem it solves
Earlier encodings such as ASCII supported only English, and national encodings were mutually incompatible. UTF-8 handles all scripts and keeps ASCII unchanged.
U+0041 A -> 41
U+00E9 e-acute -> C3 A9
U+20AC Euro -> E2 82 AC
U+1F600 emoji -> F0 9F 98 80Specification summary
Code points up to U+007F use one byte identical to ASCII. Higher code points use two to four bytes: a leading byte indicates the length and continuation bytes begin with the bits 10. Byte-oriented operations such as searching for ASCII characters stay valid. The encoding is self-synchronising.
Adoption
Ken Thompson and Rob Pike designed it in 1992 for Plan 9. It is the default for HTML5, JSON (JSON), and most modern programming languages and file systems.
Status and versioning
RFC 3629 (2003) limits the code space to U+10FFFF, matching UTF-16.
Unicode code points and byte sequences
Unicode assigns code points to characters and related symbols. UTF-8 is one way to encode those code points as bytes. A code point in the ASCII range U+0000 through U+007F is represented by the same single byte used by ASCII. Other code points use two, three or four bytes. The leading byte indicates the sequence length, and continuation bytes have a distinctive bit pattern that helps a decoder find character boundaries.
UTF-8 is variable-width. A text file containing mostly English letters may use close to one byte per character, while text with many characters outside the ASCII range uses more. This is a space trade-off: a single fixed-width encoding would simplify some indexing operations but waste space for many common texts. UTF-8's byte structure makes it efficient for typical web and document data while supporting all valid Unicode code points.
Validity and self-synchronisation
UTF-8 is designed so a decoder can identify the beginning of a sequence by examining byte patterns. If a program starts reading at an arbitrary byte position, it can often find the next character boundary without needing to decode the entire file from the beginning. This is known as self-synchronisation and is useful for text processing and recovery from some forms of corruption.
Not every sequence of bytes is valid UTF-8. Overlong encodings, surrogate code points and values beyond the Unicode maximum are invalid. Software that decodes UTF-8 must decide how to handle malformed sequences: it may report an error, replace invalid data or use another explicit policy. Silently treating arbitrary bytes as characters can create security and data-integrity problems.
Characters are not always one code point
A common misconception is that one visible character always corresponds to one Unicode code point or one byte. A user-perceived character may be represented by multiple code points, such as a base letter followed by a combining accent. Emoji can use variation selectors, skin-tone modifiers and zero-width joiners to form sequences that display as one graphic. UTF-8 encodes each code point in those sequences, but it does not define how a font renders them or how a user interface counts them.
This distinction affects string length, cursor movement and text selection. A programming language may report the number of bytes, code points or code units, depending on its string representation. User interfaces often need grapheme-cluster-aware operations to avoid splitting a visible character while editing text.
Adoption across the web and software
UTF-8 became the dominant encoding for web content because it supports international text while remaining compatible with ASCII for the basic Latin range. HTML documents commonly declare UTF-8 in their metadata, JSON exchanges use Unicode text, and modern programming environments generally provide UTF-8 support. The encoding is also used in many file systems, programming-language source files and network protocols.
Interoperability still depends on correct declarations and consistent decoding. A file saved in one encoding but interpreted as another can display mojibake: readable bytes become unrelated symbols. Applications should define the expected encoding at boundaries, preserve original data where necessary and avoid guessing encodings when a reliable declaration exists.
Practical guidance
Developers should keep text as Unicode in application logic and encode it to UTF-8 when writing to files or sending data through interfaces that specify UTF-8. They should distinguish bytes from text, validate untrusted input and use libraries that understand Unicode boundaries. Case conversion, sorting and character classification can depend on locale and Unicode version, so byte-level operations are not suitable for every text task.
UTF-8 is successful because it is simple to exchange and efficient for a wide range of languages. It solves the byte-encoding problem, not every problem associated with human language. Correct text handling also requires normalisation choices, grapheme-aware editing, font support and language-sensitive behaviour.
Encoding in networked applications
A service should state which character encoding it expects at each boundary, especially when accepting text from browsers, files or external APIs. Correct decoding prevents corrupted names and can also avoid security bugs caused by inconsistent interpretation between components. Validation should occur after decoding, and applications should not assume that every byte sequence is valid text. Consistent UTF-8 handling makes internationalisation more reliable, but applications still need to account for language-specific sorting, case conversion and input methods.
Editorial connections and engineering implications
Unicode code points are abstract values; UTF-8 defines how those values are represented as bytes. A visible character is not always one code point: accented letters can use combining marks, and emoji may consist of several code points joined together. Counting bytes, code points and displayed grapheme clusters can therefore produce different results. User interfaces should use grapheme-aware operations when counting visible characters.
Unicode normalisation helps compare canonically equivalent sequences, but compatibility normalisation can remove distinctions relevant to specialised text. Security-sensitive systems should also consider confusable characters and bidirectional controls. Applications should specify UTF-8 at system boundaries and handle malformed sequences deliberately rather than silently guessing an encoding. UTF-8 preserves the first 128 code points of ASCII and is central to JSON and modern web protocols.
See also
- ASCII – A 7-bit character encoding that assigns numbers to 128 letters, digits, symbols and control codes.
- JSON – A lightweight text format for structured data based on JavaScript object syntax.
- HTML – The standard markup language used to structure documents and applications on the World Wide Web.
- POSIX – A family of IEEE standards that specify a portable interface for Unix-like operating systems.
- TLS 1.3 – The 2018 version of the Transport Layer Security protocol for encrypted network communication.
