Unicode 標準

コード単位

エンコーディングの最小単位:UTF-8では8ビットバイト、UTF-16では16ビットワード、UTF-32では32ビットワード。1つの文字が複数のコード単位を必要とする場合があります。

· Updated

What is a Code Unit?

A code unit is the minimal bit combination used in a Unicode encoding. Different encodings use different code unit sizes:

  • UTF-8: 8-bit code units (bytes)
  • UTF-16: 16-bit code units (2-byte words)
  • UTF-32: 32-bit code units (4-byte words)

A code unit is not the same as a code point. Code points are abstract Unicode values (U+0000–U+10FFFF); code units are the concrete building blocks that encodings use to represent those values. One code point may require one or more code units depending on the encoding and the code point's value.

Code Units by Encoding

UTF-8 (8-bit code units)

UTF-8 uses 1 to 4 bytes per code point, following a variable-length scheme:

Code point range Code units Byte pattern
U+0000–U+007F 1 0xxxxxxx
U+0080–U+07FF 2 110xxxxx 10xxxxxx
U+0800–U+FFFF 3 1110xxxx 10xxxxxx 10xxxxxx
U+10000–U+10FFFF 4 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
'A'  (U+0041) → 1 code unit:  0x41
'é'  (U+00E9) → 2 code units: 0xC3 0xA9
'中' (U+4E2D) → 3 code units: 0xE4 0xB8 0xAD
'😀' (U+1F600) → 4 code units: 0xF0 0x9F 0x98 0x80

UTF-16 (16-bit code units)

BMP characters (U+0000–U+FFFF) use 1 code unit. Supplementary characters use 2 code units (a surrogate pair):

'A'  (U+0041)  → 1 code unit:  0x0041
'中' (U+4E2D)  → 1 code unit:  0x4E2D
'😀' (U+1F600) → 2 code units: 0xD83D 0xDE00  (surrogate pair)

UTF-32 (32-bit code units)

Every code point uses exactly 1 code unit — UTF-32 is the only fixed-width Unicode encoding:

'A'  (U+0041)  → 0x00000041
'中' (U+4E2D)  → 0x00004E2D
'😀' (U+1F600) → 0x0001F600

Why Code Units Matter in Programming

Many programming languages expose string length in terms of code units, not code points or grapheme clusters:

s = "😀"
len(s)               # Python 3: 1 — counts code points (Unicode scalars)
len(s.encode("utf-8"))  # 4 — UTF-8 code units (bytes)
"😀".length          // 2 — JavaScript counts UTF-16 code units
[..."😀"].length     // 1 — spread iterator counts code points
String s = "😀";
s.length()           // 2 — Java String.length() counts UTF-16 code units
s.codePointCount(0, s.length()) // 1 — code point count

This is a common source of bugs: naive string slicing by index in JavaScript or Java can split a surrogate pair, producing invalid text.

Common Pitfalls

Confusing code units with bytes: A UTF-16 code unit is 2 bytes, not 1. A string of length n in a Java String occupies at least 2n bytes.

Assuming 1 code unit = 1 character: A single user-visible character (grapheme cluster) may require multiple code points, each potentially requiring multiple code units.

Slicing strings at byte offsets: UTF-8 continuation bytes begin with 10xxxxxx. Slicing between them produces invalid UTF-8 sequences.

Quick Facts

Property Value
UTF-8 code unit size 8 bits (1 byte)
UTF-16 code unit size 16 bits (2 bytes)
UTF-32 code unit size 32 bits (4 bytes)
UTF-8 code units per BMP char 1–3
UTF-16 code units per BMP char 1
UTF-16 code units per supplementary char 2 (surrogate pair)
Only fixed-width encoding UTF-32
Language using UTF-16 internally Java, JavaScript (V8), C# (.NET), Windows

関連用語

Unicode 標準 のその他の用語

CJK(漢字・かな・ハングル)

中国語・日本語・韓国語 — Unicodeにおける統合漢字ブロックと関連スクリプトをまとめた総称。CJK統合漢字は20,992文字以上を含みます。

Han Unification

The process of mapping Chinese, Japanese, and Korean ideographs that share a …

Hangul Jamo

The individual consonant and vowel components (jamo) of the Korean Hangul writing …

ISO 10646 / 万国文字集合

Unicodeと同期している国際標準(ISO/IEC 10646)で、同じ文字目録とコードポイントを定義しますが、Unicodeの追加アルゴリズムやプロパティは含みません。

Unicode

あらゆる文字システムのすべての文字に固有の番号(コードポイント)を割り当てる普遍的文字エンコーディング規格。バージョン16.0には154,998個の割り当て済み文字が含まれます。

Unicode Standard Annex (UAX)

Normative or informative documents that are integral parts of the Unicode Standard. …

Unicode Technical Report (UTR)

Informational documents published by the Unicode Consortium covering specific topics like security …

Unicode コンソーシアム

Unicode標準を開発・維持する非営利団体。Apple・Google・Microsoft・Metaなど多くの企業が会員です。

Unicode スカラー値

サロゲートコードポイント(U+D800〜U+DFFF)を除くすべてのコードポイント。実際の文字を表すことができる有効な値の集合で、合計1,112,064個です。

Unicode バージョン

新しい文字・文字体系・機能を追加するUnicode標準の主要リリース。現在のバージョンはUnicode 16.0(2025年9月)です。