← Glossary

What a surrogate pair is

Last updated: 2026-10-31/~4 min

This article takes about 4 minutes to read.

A phenomenon in which you type a single emoji, yet it is counted as "2 characters". What lies behind it is the surrogate pair.When you try to handle the range Unicode can represent with UTF-16, a design based on 16-bit units, there are cases where you have no choice but to use 2 "halves" to represent one character. This pair of halves is called a surrogate pair. It is a basic concept that comes up when handling emoji and some kanji.

Definition

A surrogate pair is the mechanism in UTF-16 that represents a Unicode codepoint above U+FFFF with two 16-bit units. The first half is called the "high surrogate" (High Surrogate, U+D800 to U+DBFF) and the second half the "low surrogate" (Low Surrogate, U+DC00 to U+DFFF), and these 2 always appear as a pair.

Why it is needed

Unicode has a vast codepoint space from U+0000 to U+10FFFF. Representing it requires 21 bits. However, because UTF-16 is designed with 16 bits per unit, it can represent only up to U+FFFF on its own. To handle characters beyond this limit (most emoji, some kanji, ancient scripts, mathematical symbols, and so on), a mechanism that extends the range by combining a high and a low half was introduced.

How it relates to emoji

Many emoji codepoints are in the range from U+1F000 onward, and in UTF-16 they are represented with surrogate pairs. For example, 🌸 (U+1F338) is stored in UTF-16 as the two 16-bit units D83C DF38. This fact is the direct cause of a single emoji counting as 2 in JavaScript string length counts.

How JavaScript behaves

Because a JavaScript String is represented internally in UTF-16, .length counts a surrogate pair as 2.

ExpressionResultMeaning
"あ".length1Within the BMP, so no pair is needed
"🌸".length2Made of a surrogate pair
[..."🌸"].length1Split by codepoint
"🌸".codePointAt(0)127800The combined codepoint value

How it differs from UTF-8 / UTF-32

The surrogate pair is a mechanism specific to UTF-16. UTF-8 can represent every codepoint with a variable length of 1 to 4 bytes, and UTF-32 handles every codepoint as one unit with a fixed 4 bytes. In languages / runtimes that use UTF-8 or UTF-32 as their internal representation, the concept of surrogate pairs does not come to the surface.

How it matters in practice

  • Character count validation: Understanding surrogate pairs is necessary when you want to count a form's maximum length in "characters as humans perceive them"
  • Text processing: Extracting substrings, reversing, and regular expression matching need to treat a surrogate pair as one unit
  • File names / databases: Cases where data containing emoji is corrupted in systems that cannot handle surrogate pairs correctly
  • Character counts on social media: Differences in each platform's counting logic also arise from differences in how they handle surrogate pairs and grapheme clusters

How to count correctly

If you want to count in units that users perceive as "1 character", you need to count by grapheme cluster, not by surrogate pair. In JavaScript environments that have Intl.Segmenter, emoji and ZWJ sequences can also be properly treated as one unit.

Common misconceptions

  • ❌ "All emoji count as 2 characters" → ✅ Emoji at or below U+FFFF (some older symbols) need no pair and count as 1 character
  • ❌ "Surrogate pairs are used in UTF-8 too" → ✅ It is a mechanism specific to UTF-16
  • ❌ "A high surrogate on its own is still a valid character" → ✅ On its own it makes an invalid Unicode string (Unpaired Surrogate)

Related terms

  • Unicode - the international standard for characters
  • Emoji - often represented with surrogate pairs

Was this article helpful?