UTF-8 vs UTF-16 — What's the Difference?
Both are encodings for representing Unicode characters as bytes, but UTF-8 uses 1 to 4 bytes per character (and is backward-compatible with ASCII), while UTF...
Published November 24, 2026
UTF-8 and UTF-16 are two ways to encode Unicode as bytes. UTF-8 uses 1–4 bytes per character and is ASCII-compatible, making it the standard on the web; UTF-16 uses 2 or 4 bytes and is used internally by JavaScript, Java and Windows.
The concept
UTF-8: ASCII characters take 1 byte, so English text stays small; most other scripts take 2–3 bytes and emoji 4.
UTF-16: most common characters take 2 bytes, others use surrogate pairs (4 bytes). It has byte-order issues (BOM) that UTF-8 avoids.
Bytes per character
Practical examples
Measure byte length
new TextEncoder().encode('₹').length // 3 (UTF-8)
'₹'.length // 1 (UTF-16 unit)Declare UTF-8
<meta charset="utf-8">HTTP header
Content-Type: text/html; charset=utf-8Python
'₹'.encode('utf-8') # 3 bytes
'₹'.encode('utf-16') # includes BOMCommon mistakes
- Serving pages without a charset.
- Counting UTF-16 length as characters for emoji.
- Mixing encodings between database and app.
Key takeaways
- UTF-8 is variable, ASCII-compatible, the web default.
- UTF-16 is common in language runtimes.
- Always declare the encoding.
FAQ
Why is UTF-8 preferred?
Compact for ASCII, no endianness issues and universally supported.
What is a BOM?
A byte-order mark signalling encoding/endianness at file start.