UTF-16 Encoding Guide

UTF-16 Encoding Guide

The 16-bit-unit encoding used by Windows APIs, Java, and JavaScript string internals.

Code units and the BMP

UTF-16 stores most characters as one 16-bit code unit. Characters in the Basic Multilingual Plane, from U+0000 to U+FFFF, fit directly.

The Latin letter A is 0041 and the euro sign is 20AC in UTF-16.

A0041
20AC

Surrogate pairs for astral code points

Code points above U+FFFF do not fit in one 16-bit unit, so UTF-16 uses a surrogate pair: a high surrogate in D800-DBFF followed by a low surrogate in DC00-DFFF.

The grinning face U+1F600 becomes D83D DE00. A single JavaScript string character can therefore be two UTF-16 code units.

😀D83D DE00

Byte order

UTF-16 text can be written as UTF-16LE or UTF-16BE depending on byte order. A byte order mark at the start helps decoders detect the order.

On the web, UTF-8 is preferred because UTF-16 doubles the size of ASCII text and creates edge cases with partial surrogates.