Skip to content
uencoder

UTF-8

UTF-8 is Unicode's variable-length encoding form, using 1 to 4 bytes per code point; it is fully backward compatible with ASCII and is the de facto standard for the web and modern systems.

Purpose

It covers all Unicode code points while staying ASCII-compatible (no expansion for English), and is byte-order independent and self-synchronizing, which suits network transport.

Mechanism

The code point range determines the byte length: U+0000-007F takes 1 byte; U+0080-07FF takes 2; U+0800-FFFF takes 3; U+10000-10FFFF takes 4. The number of leading 1 bits in the first byte indicates the sequence length.

Use cases

  • Default encoding of HTML / XML / JSON documents
  • HTTP and email body transport
  • Source code file encoding
  • Default database character set

Examples

  • Input
    A
    Output
    0x41

    An ASCII character, 1 byte

  • Input
    U+4E2D
    Output
    0xE4 0xB8 0xAD

    A BMP CJK ideograph, 3 bytes

Common errors

Truncating a UTF-8 string mid-sequence, producing invalid bytes
Truncate at character boundaries or use encoding-aware APIs

Related terms

Related tools

References