L
LLLOS.ai
Learn
L

Ask Your Tutor · Computer Science

What is a surrogate pair in UTF-16?

From NCERT Asked by Anonymous from Bordeaux, France 24 Oct 2026, 3:11 AM IST Updated

In one line

A surrogate pair in UTF-16 is two special code units that together represent one character outside the Basic Multilingual Plane (BMP).

The rule

In UTF-16, a surrogate pair is a combination of two 16-bit code units (one high surrogate and one low surrogate) used to encode characters with code points above U+FFFF.

There is no simple formula, but:

  • High surrogate: from U+D800 to U+DBFF
  • Low surrogate: from U+DC00 to U+DFFF

Let's understand it simply

Imagine you have a box that can hold numbers up to 65,535 (this is what 16 bits can store). Most letters and symbols fit in this box. But some rare characters, like certain emojis or old scripts, need bigger numbers. UTF-16 solves this by using two boxes together for these big numbers. These two boxes are called a surrogate pair. One is the "high surrogate" (first part), and the other is the "low surrogate" (second part). Together, they store one big character.

How it works

  1. UTF-16 normally uses one 16-bit code unit for each character.
  2. If a character's code point is above U+FFFF (like some emojis), it can't fit in one unit.
  3. UTF-16 splits the big number into two parts.
  4. The first part goes into a high surrogate (between U+D800 and U+DBFF).
  5. The second part goes into a low surrogate (between U+DC00 and U+DFFF).
  6. When a computer reads these two together, it knows they mean one special character.
How a surrogate pair works in UTF-16
  1. See a character above U+FFFF (like 😀)
  2. Split its code point into two parts
  3. Store first part in high surrogate (U+D800–U+DBFF)
  4. Store second part in low surrogate (U+DC00–U+DFFF)
  5. Together, they represent one character

The story behind it

When computers started using Unicode, they needed a way to store over a million characters. But many computers worked best with 16 bits. So, in the 1990s, UTF-16 was made. Surrogate pairs were invented to let UTF-16 handle all Unicode characters, not just the first 65,536.

Where you see it in real life

  • 600 (😀, the grinning face emoji): Needs a surrogate pair in UTF-16.
  • Some rare Chinese, Japanese, or old Indian script characters: Also need surrogate pairs.
  • When you type certain emojis on WhatsApp or Instagram, your phone uses surrogate pairs to store them.
  • In programming, if you count "characters" in a string with emojis, you might get more than you expect because of surrogate pairs.

Why it matters

  • Lets computers store and show all world languages and symbols, not just basic ones.
  • Needed for modern apps, websites, and phones that use emojis and rare scripts.
  • Important for programmers: handling text correctly (like counting characters) needs understanding surrogate pairs.
  • Used in many programming languages (like Java, JavaScript, Python) when working with text.

Common mistakes

  • Thinking every character is one code unit in UTF-16 (not true for emojis and rare symbols).
  • Ignoring surrogate pairs when counting characters: "😀" is two code units, not one.
  • Mixing up high and low surrogates: order matters.

Remember it

Surrogate pair = two 16-bit pieces for one big character in UTF-16.

Check yourself

What is a surrogate pair in UTF-16?

Two 16-bit code units that together represent one character above U+FFFF.

Why do we need surrogate pairs?

Because some characters (like emojis) need more than 16 bits to store.

If a string has the emoji 😀, how many UTF-16 code units does it use?

Two code units, because it is stored as a surrogate pair.

What happens if you count code units instead of characters in a string with emojis?

You may get a bigger number, since each emoji uses two code units.

Quick recap

  • A surrogate pair in UTF-16 uses two code units for one character.
  • Needed for characters with code points above U+FFFF (like emojis).
  • High surrogate comes first, then low surrogate.
  • Counting characters in UTF-16 can be tricky because of surrogate pairs.
  • Surrogate pairs help computers handle all Unicode characters.
Written by the LLOS.ai tutor, checked against NCERT chapters. Asked by Anonymous from Bordeaux, France on 24 Oct 2026, 3:11 AM IST