Imagine you want to write a big number, but your notebook only has space for 4 digits on each page. If your number is too big, you split it across two pages. Similarly, in computers, the normal way (UTF-16) can only store up to U+FFFF in one piece. For bigger numbers (above U+FFFF), we break them into two parts, called a surrogate pair. Each part fits into the 16-bit space.
How it works
Write the character's code point (for example, U+1F600 for 😀).
Subtract 0x10000 (65536 in decimal) from it. This gives you a 20-bit number.
Take the top 10 bits of this number. Add 0xD800 (55296) to get the high surrogate.
Take the bottom 10 bits. Add 0xDC00 (56320) to get the low surrogate.
Write both surrogates in order. Together, they represent your character in UTF-16.
Converting a code point above U+FFFF to a surrogate pair
Write the code point (e.g., U+1F600)
Subtract 0x10000
Split into top 10 and bottom 10 bits
Add 0xD800 to top 10 bits for high surrogate
Add 0xDC00 to bottom 10 bits for low surrogate
Write both surrogates in order
The story behind it
When Unicode was first made, it was thought 16 bits (U+0000 to U+FFFF) would be enough. But later, more characters were needed (like emojis, rare scripts). UTF-16 was updated to use surrogate pairs, so computers could handle all these new symbols without breaking old software.
Where you see it in real life
600 (😀) emoji: Needs a surrogate pair in UTF-16 to be stored or shown.
Ancient scripts: Some rare Indian scripts (like Brahmi) use code points above U+FFFF.
Musical symbols: Special notes and marks in sheet music apps.
Some maths symbols: Used in scientific calculators or maths software.
Programming: When you type or process emojis in Python, Java, or JavaScript, they use surrogate pairs inside.
Why it matters
Lets computers store and show all world scripts, emojis, and symbols.
Needed for modern apps, websites, and phones that use emojis or rare scripts.
Important for programmers working with text, especially in Indian languages.
Questions on Unicode and encoding come in computer science exams.