Skip to content
uencoder

Surrogate Pair

A surrogate pair is the UTF-16 mechanism that represents one supplementary-plane code point (U+10000 through U+10FFFF) using two 16-bit code units.

Purpose

It lets UTF-16 cover all of Unicode beyond the BMP with 16-bit code units, while keeping 1-unit efficiency for BMP characters.

Mechanism

Subtract 0x10000 from a supplementary code point C to get a 20-bit value in 0-0xFFFFF; the high 10 bits plus 0xD800 give the high surrogate (0xD800-0xDBFF) and the low 10 bits plus 0xDC00 give the low surrogate (0xDC00-0xDFFF). Decoding runs the computation in reverse.

Use cases

  • Emoji string handling (e.g., 😀 = U+1F600)
  • JavaScript string length and iteration
  • Wide-character handling in Windows APIs
  • Rendering of ancient scripts and rare characters

Examples

  • Input
    😀
    Output
    \uD83D\uDE00

    High surrogate D83D plus low surrogate DE00

Common errors

Splitting a surrogate pair by truncating mid-pair, creating lone surrogates
Iterate code points with for...of or Array.from

Related terms

Related tools

References