A code point is a numerical position in the code space of a character encoding. In Unicode, code points identify abstract characters, such as letters, digits, and punctuation, as well as control characters and other designated values. A code point is distinct from the bytes used to store it, the graphical shape used to display it, and the text unit that a reader perceives as a single character.
Definition and notation
A character encoding defines a code space: a set or range of numerical positions. A code point is any position in that space, whether or not a character has been assigned to it.
Unicode code points range from hexadecimal 0000 through 10FFFF, inclusive. They are conventionally written with the prefix U+ followed by four to six hexadecimal digits:
| Code point | Unicode name | Example |
|---|---|---|
U+0041 |
LATIN CAPITAL LETTER A | A |
U+00E9 |
LATIN SMALL LETTER E WITH ACUTE | é |
U+0301 |
COMBINING ACUTE ACCENT | A mark that combines with a preceding character |
U+4E2D |
CJK UNIFIED IDEOGRAPH-4E2D | 中 |
U+1F600 |
GRINNING FACE | 😀 |
The U+ notation identifies a numerical value; it does not specify how that value is represented in memory or transmitted over a network. For example, U+0041 may be represented by different byte sequences in different Unicode encoding forms.
The term also applies outside Unicode. In ASCII, the capital letter A occupies code point 65, or hexadecimal 41. The same numerical position can represent different characters in unrelated character encodings, so its interpretation depends on the encoding.
Code points, characters, and glyphs
Several distinct units are often informally called “characters.”
- An abstract character is a unit of textual information, independent of a particular visual appearance.
- A code point is a numerical position in a code space.
- A code unit is the basic numerical unit used by an encoding form to represent text.
- A grapheme cluster is a sequence of code points treated as a single text element by Unicode text-segmentation rules, approximating a user-perceived character.
- A glyph is a graphical form used to display text.
These units do not have a one-to-one relationship. A single abstract character can sometimes be represented by different code-point sequences. A single grapheme cluster can contain multiple code points, while a font can render multiple characters together as one glyph, as in a ligature.
For example, the letter é can be represented as:
U+00E9, a single precomposed character; orU+0065 U+0301, the letter e followed by a combining acute accent.
These sequences are canonically equivalent in Unicode, but their code points and encoded bytes differ. Unicode normalization provides standardized transformations for handling such equivalences.
Code points also need not produce visible marks. Control characters, combining marks, variation selectors, and formatting characters can affect text processing or presentation without appearing as independent symbols. Conversely, some emoji displayed as a single image consist of several code points joined into one sequence.
Organization of the Unicode code space
Unicode contains:
code points. The code space is divided into 17 planes, each containing 65,536 positions.
Plane 0, from U+0000 through U+FFFF, is the Basic Multilingual Plane. It contains many widely used writing systems, common symbols, and the surrogate range. Planes 1–16 are supplementary planes, containing additional scripts, symbols, emoji, ideographs, private-use areas, and other designated ranges.
A Unicode block is a named, contiguous range within this space. Blocks are organizational divisions, not necessarily complete writing systems: a script may occupy several blocks, and a block may include characters shared by multiple scripts.
Assigned and unassigned positions
Not every code point has an assigned character. Important categories include:
- Assigned characters: positions with defined character identities, including graphic, control, and formatting characters.
- Unassigned code points: positions available for possible assignment in later versions.
- Private-use code points: positions whose meanings are determined by private agreement rather than standardized character assignments.
- Surrogate code points: the range
U+D800–U+DFFF, reserved for the UTF-16 encoding mechanism. - Noncharacters: 66 permanently designated code points reserved for internal use rather than ordinary character interchange.
Noncharacters are distinct from both unassigned positions and private-use characters. They are Unicode scalar values and can be encoded in well-formed Unicode text, although they are not intended to represent abstract characters for open interchange.
Unicode scalar values
A Unicode scalar value is any Unicode code point except a surrogate code point:
There are 2,048 surrogate code points, leaving 1,112,064 scalar values. These include unassigned positions, private-use positions, and noncharacters—not just assigned characters.
The distinction matters because the well-formed Unicode encoding forms represent scalar values. An isolated surrogate is a code point, but it is not a scalar value and cannot occur in a well-formed UTF-8 or UTF-16 sequence.
Relationship to encoding forms
A code point is independent of the encoding form used to store it. Unicode encoding forms map scalar values to sequences of code units.
| Encoding form | Code-unit size | Code units per scalar value |
|---|---|---|
| [[utf-eight | UTF-8]] | 8 bits |
| [[utf-sixteen | UTF-16]] | 16 bits |
| [[utf-thirty-two | UTF-32]] | 32 bits |
For example, U+1F600 is represented as:
- UTF-8: four bytes,
F0 9F 98 80; - UTF-16: two code units,
D83D DE00; - UTF-32: one code unit,
0001F600.
In UTF-16, the two units form a surrogate pair. Neither unit by itself represents the emoji. Encoding supplementary code points as pairs enabled UTF-16 to extend beyond the original 16-bit range while retaining single-unit representations for nonsurrogate characters in the Basic Multilingual Plane.
A byte count therefore need not equal a code-point count. Byte order is a separate issue: when UTF-16 or UTF-32 code units are serialized as bytes, their ordering must be specified. A byte order mark can help identify that ordering in contexts that permit it.
Role in software
Code points provide stable identifiers for character properties and operations such as case conversion, script detection, searching, and text segmentation. Nevertheless, operating on code points is not sufficient for every text-processing task.
Length and indexing
String length depends on the unit being counted. In JavaScript, ordinary string length and indexed access use UTF-16 code units. Consequently, "😀".length is 2, although the string represents one code point. JavaScript string iteration combines well-formed surrogate pairs, while still exposing lone surrogates if present.
In Python, strings are sequences of Unicode code points, so len("😀") is 1. However, len("e\u0301") is 2 even though the sequence commonly appears as one user-perceived character.
Text editors, cursor movement, and user-facing character limits may therefore require grapheme-cluster boundaries rather than code-point boundaries.
Ordering and comparison
Numerical code-point order is not generally linguistic order. Alphabetization depends on language, locale, accents, case, and conventions governing character sequences. Unicode collation addresses comparison beyond raw numerical ordering.
Likewise, two strings that appear identical may contain different code points. Canonical normalization resolves certain equivalences, but it does not make all visually similar characters identical. A Latin letter and a similar-looking Cyrillic letter can remain distinct, which is relevant to identifier handling and cybersecurity.
Validation and malformed text
Decoding converts encoded code units into text. Malformed input, such as an invalid UTF-8 sequence or an unpaired UTF-16 surrogate, requires an error-handling policy. Depending on the format and software interface, a decoder may reject the input or replace malformed sequences with U+FFFD REPLACEMENT CHARACTER.
Checking encoding well-formedness is separate from checking whether a code point is assigned, supported by a font, or permitted in a particular field. An unassigned scalar value can have a well-formed encoding, and an assigned character may display as a missing-glyph symbol when a suitable font is unavailable.