Unicode Normalization Explained: NFC vs NFD vs NFKC vs NFKD
What the four Unicode normalization forms do, how NFC, NFD, NFKC and NFKD differ, how to convert NFD to NFC, and when normalization is the wrong fix.
Direct answer
Unicode normalization converts text into a standard sequence of code points, so strings that look identical also compare as identical. There are four forms:
| Form | Decomposition | Recomposes? | Changes meaning? | Typical use |
|---|---|---|---|---|
| NFC | Canonical | Yes | No | Storing and displaying text (the web default) |
| NFD | Canonical | No | No | Processing accents separately, some file systems |
| NFKC | Compatibility | Yes | Can | Search keys, usernames, deduplication |
| NFKD | Compatibility | No | Can | Accent-insensitive matching, text analysis |
Use NFC for text people will read. Use NFKC only for matching, and keep the original text.
Why the same text can have different code points
The character é can be stored two ways:
- as one precomposed code point,
U+00E9(LATIN SMALL LETTER E WITH ACUTE), or - as
e(U+0065) followed by the combining acute accentU+0301.
Both render as é. But a program comparing them code point by code point sees two different strings: one is 1 code point long, the other 2. That causes real bugs:
- Search misses: a search for
résuméin one form will not match the other. - Length surprises: character limits count the decomposed form as longer.
- Duplicate records: two usernames or tags that look the same are stored twice.
- Regex failures: a pattern that expects one character per letter can split an accent from its base letter.
Normalization fixes this by picking one representation.
NFC vs NFD: the canonical forms
Canonical equivalence means two sequences are the same character, not just similar-looking ones. NFC and NFD only convert between canonically equivalent sequences, so they are always safe to apply.
- NFD (Normalization Form Canonical Decomposition) splits characters into a base letter plus combining marks:
é→e+U+0301. - NFC (Normalization Form Canonical Composition) decomposes and then recomposes wherever a precomposed character exists:
e+U+0301→é.
Most text on the web, and most text typed on Windows, Android and iOS keyboards, is already in NFC. NFD text often comes from older macOS file names (HFS+ stored names decomposed) and from tools that strip accents by decomposing first.
How to convert NFD to NFC
- JavaScript:
text.normalize('NFC') - Python:
unicodedata.normalize('NFC', text) - Java:
Normalizer.normalize(text, Normalizer.Form.NFC)
Already-composed text is left unchanged, so running NFC twice is harmless. To go the other way, pass 'NFD'.
NFKC and NFKD: the compatibility forms
Compatibility equivalence is looser. It treats characters as the same if they are formatting or presentation variants of one another. NFKC and NFKD fold those variants into a plain character:
| Input | Code point | After NFKC |
|---|---|---|
| fi (ligature) | U+FB01 | fi |
| A (full-width A) | U+FF21 | A |
| ² (superscript two) | U+00B2 | 2 |
| ① (circled digit one) | U+2460 | 1 |
| ½ (vulgar fraction) | U+00BD | 1⁄2 |
| No-break space | U+00A0 | normal space (U+0020) |
| Narrow no-break space | U+202F | normal space (U+0020) |
- NFKC (Compatibility Composition) folds the variants and then recomposes accents, so
éstays one code point. - NFKD (Compatibility Decomposition) folds the variants and leaves accents decomposed.
When NFKC is the right choice
NFKC is useful when you need two strings to match, not when you need to display them:
- search indexes and query normalization
- usernames and identifiers, so that
paypalandpaypalare treated as the same name - deduplicating tags, keywords, or records
When NFKC causes damage
Because it changes characters, NFKC can lose information. x² becomes x2, ½ becomes 1⁄2, and full-width text used deliberately in Chinese and Japanese layout becomes half-width. Do not run NFKC over articles, documents, or code you intend to publish. Store the original, and keep the NFKC version only as a matching key.
What normalization does not fix
Normalization is often mistaken for a general “clean up the text” step. It is not:
- Zero-width spaces (U+200B), the byte order mark (U+FEFF) and soft hyphens (U+00AD) survive every normalization form. They have no decomposition, so NFC, NFD, NFKC and NFKD all leave them in place.
- Zero-width joiners and non-joiners (U+200D, U+200C) are also kept, which is correct, because emoji and scripts such as Persian and Urdu depend on them.
- Normalization does not touch wording, so it has no effect on AI detection or on a statistical watermark.
To remove hidden characters, use the Invisible Character Remover, which lists each one by name. The site's cleaners work on characters and spacing; they do not apply NFC or NFKC, so run normalize() yourself if your workflow needs a specific form. For more on finding hidden code points, see how to detect hidden Unicode characters.
A safe order of operations for pasted text
- Inspect the text for hidden characters and unusual spaces.
- Remove stray zero-width spaces, BOMs and soft hyphens with a cleaner.
- Normalize to NFC for storage and display.
- Derive an NFKC key only if you need matching or search, and keep it separate.
Bottom line
NFC and NFD change how text is stored without changing what it means. NFKC and NFKD fold look-alike characters together, which helps matching but can lose information. None of the four removes zero-width spaces, so treat normalization and hidden-character cleaning as two separate steps.
