# Unicode Normalization: NFC, NFD, NFKC, NFKD, and Real-World Pitfalls

> Understand canonical and compatibility equivalence, choose the right normalization form for storage, search, and identifiers, and avoid case-folding and grapheme bugs.

**Quick answer:** Unicode normalization maps code point sequences that represent the same abstract text onto one chosen form. NFC and NFD preserve canonical equivalence; NFKC and NFKD also fold compatibility variants such as circled digits, ligatures, and fullwidth letters. Normalize both sides of every comparison, choose the form per field, and never treat normalization as sanitization or as a substitute for case folding.

## Key takeaways

- NFC and NFD are lossless and interchangeable; NFKC and NFKD are lossy because they collapse compatibility distinctions such as circled digits, ligatures, and fullwidth letters.
- Normalize after concatenation as well as before comparison, because two NFC strings can join to form a non-NFC string at the boundary.
- Case folding is not lowercasing: Turkish dotless i, German sharp s, and Greek final sigma behave differently under the two operations.
- String length counts UTF-16 code units, code points, or grapheme clusters depending on the API; use Intl.Segmenter when the product promise is about visible characters.
- Normalization never makes two confusable strings identical and never sanitizes control characters, bidi overrides, or markup; UTS #39 and an input policy are separate defenses.

---

Two strings can look identical and still be different byte sequences. The letter `é` may arrive as U+00E9 or as U+0065 followed by U+0301, a combining acute accent. A Korean syllable may arrive precomposed or as two Jamo letters. A search box, username check, or password hash that compares raw strings will disagree with the user about what was typed.

Normalization maps such sequences onto a shared representative form. It is a small API with a large blast radius: applied at the wrong layer it breaks signatures, locks users out, changes legal text, or hides duplicate identifiers. This guide covers what each form promises and how to verify the result.

## What Unicode normalization actually does

Unicode assigns a code point to every abstract character but does not require one encoding per visual result. Precomposed characters, combining sequences, ligatures, and width variants can represent the same text. UAX #15 defines four normalization forms.

The driving distinction is equivalence. Canonically equivalent sequences represent the same abstract character and must compare identical. Compatibility equivalents represent the same text only in limited contexts, such as a ligature standing for two letters, and folding them deliberately loses formatting.

| Form | Decomposes | Recomposes | Equivalence removed | Best used for |
| --- | --- | --- | --- | --- |
| NFC | Canonical | Yes | Canonical only | Storage, display, interchange |
| NFD | Canonical | No | Canonical only | Per-code-point processing, some filesystem paths |
| NFKC | Compatibility and canonical | Yes | Compatibility and canonical | Search keys, identifier skeletons, legacy cleanup |
| NFKD | Compatibility and canonical | No | Compatibility and canonical | Folding pipelines, text indexing |

Two properties matter. Normalization is idempotent: normalizing an already-normalized string in the same form returns it unchanged. It is not compositional: concatenating two NFC strings does not guarantee NFC, because characters at the join can compose. Normalize after concatenation or at a final boundary. The [Unicode code point tool](/tools/unicode) shows whether a pasted value is precomposed before you write comparison code.

## Canonical equivalence: é, Hangul, and combining marks

Canonical equivalence covers precomposed characters versus base-plus-combining decompositions, such as U+00E9 versus U+0065 U+0301, and Hangul syllables versus conjoining Jamo. NFC prefers the composed form, NFD the decomposed form, and both are lossless for ordinary characters.

Hangul is algorithmic: every syllable in the U+AC00 to U+D7A3 block decomposes into two or three Jamo, and NFC recomposes them. A syllable typed through one input method can arrive composed while the same syllable from another source arrives decomposed, which matters for Korean search and file paths.

Combining marks add canonical ordering: normalization reorders multiple marks by combining class, so sequences that differ only in mark order collapse to the same result. A few characters, such as U+0958 DEVANAGARI LETTER QA, are excluded from recomposition; NFC leaves them decomposed, so the output is stable but not the precomposed code point some code expects.

```js
const composed = "\u00E9";      // é as one code point
const decomposed = "e\u0301";  // e + COMBINING ACUTE ACCENT

composed === decomposed;                                  // false
composed.normalize("NFC") === decomposed.normalize("NFC"); // true
composed.normalize("NFD").length;                         // 2
decomposed.normalize("NFC").length;                       // 1

"\uAC00".normalize("NFD");                    // Hangul GA -> Jamo sequence
"\uAC00".normalize("NFD").normalize("NFC");   // back to U+AC00

"①".normalize("NFKC");                   // "1" (circled digit one)
"ﬁ".normalize("NFKC");                   // "fi" (Latin ligature)
"Ａ".normalize("NFKC");                   // "A" (fullwidth Latin A)
```

Normalize both operands with the same form before comparing, hashing, or enforcing a unique index. The [UTF-8 encoder](/tools/utf8) confirms that byte sequences differ and whether a transport or database driver re-encoded the text first.

## Compatibility equivalence: circled digits, ligatures, and fullwidth forms

NFKC and NFKD apply compatibility decompositions on top of canonical ones. Circled U+2460 becomes `1`, ligature U+FB01 becomes `fi`, fullwidth U+FF21 becomes `A`, Kelvin sign U+212A becomes `K`, and halfwidth katakana becomes fullwidth. These mappings help search keys, deduplication, and legacy cleanup.

They are lossy and one-way. NFKC of a circled digit is `1`, but no normalization recovers the circled form. Legal numbering, mathematics, chemical formulas, units, and brand typography depend on distinctions compatibility folding erases. Unicode's stability policy protects existing characters, but new assignments can add compatibility mappings.

NFKC converts fullwidth Latin and halfwidth katakana to standard forms, usually right for a search index and wrong for a display name. It also maps U+3000 IDEOGRAPHIC SPACE to U+0020, so whitespace trimming and normalization need a documented order; reversing it can leave a string that no longer matches its index key.

UAX #15 also defines NFKC_Casefold: NFKC, then case folding, then removal of default-ignorable code points. It is built for identifier comparison, not display, and is the closest standard collision key for usernames and table names. Treat it as input to policy, not the policy itself.

## Normalizing for storage, search, and identifiers

Choose one form, enforce it at the write boundary, and document it. NFC is the common default: compact for Latin, Greek, and Cyrillic, and matching most input methods. NFD appears in some filesystem paths, but storing NFD while querying NFC creates avoidable misses. When exact input matters, keep the original bytes and a normalized shadow column for search and uniqueness.

Search normalizes both sides with the same form, then decides how far to fold. Accent removal after NFD improves recall for `resume` versus `résumé`; NFKC handles fullwidth input; case folding handles case. Each extra step lowers precision, so measure recall and false positives on a golden query set.

Identifiers need NFKC, case folding, a UTS #39 confusable skeleton, and a script or code point allowlist. NFKC cannot stop two visually identical usernames, because Latin `p` and Cyrillic `р` are distinct characters that normalization preserves. Normalize before the uniqueness check, or the database stores `café` twice, composed and decomposed.

Filesystems vary: macOS historically normalized names to NFD on HFS+, APFS preserves bytes but compares some names normalization-insensitively, and Linux stores bytes. A file created on one platform can be invisible on another if raw names are compared. Normalize path components for comparison and preserve originals for display.

Database collation is not normalization. A case- and accent-insensitive collation can compare strings equal while an index, hash join, or cache treats them as different. Check the collation, index expression, and application normalization together; fixing one layer leaves a gap.

## Why NFKC can change meaning

NFKC is the most aggressive form and the easiest to misuse. It belongs in derived keys, not source-of-truth storage. Editorial numbering: `①` and `1` can denote different clauses in a contract. Mathematics and science: `x²` is not `x2`, and `H₂O` is not `H2O`; the Kelvin sign and the letter K are compatibility equivalents. Trademarks and typography: `™` becomes `TM`, and ligature expansion can break a brand string or fixed-width layout. Secrets: folding a password character changes the secret. Signatures: normalizing before verification can verify a different message than the one signed.

Keep a pristine copy and normalize only into derived fields. Never use NFKC as a display transform or a security filter. If a system claims it normalizes everything with NFKC for safety, ask what it stores as the original and how it handles characters NFKC does not unify, such as cross-script homoglyphs.

## Case folding is not lowercasing

Lowercasing is a locale-sensitive display transform; case folding is a Unicode operation for caseless matching. They diverge where authentication, deduplication, and search break.

Turkish: `"I".toLowerCase()` is `ı` in a Turkish locale and `i` in English. `"İ".toLowerCase()` is `i` in Turkish and often `i` plus a combining dot elsewhere. A server using the default locale can silently change identifiers a Turkish user typed. German: `"ß".toUpperCase()` is `SS`, but lowercasing leaves `ß`. Full folding maps both `ß` and `ẞ` to `ss`; simple folding does not. A lowercase-only policy may fail to collide `STRASSE` and `straße`. Greek: final sigma `ς` and medial sigma `σ` both derive from `Σ` by position; folding maps both to `σ`, while naive lowercasing may preserve the distinction.

JavaScript has no `caseFold()`. `toUpperCase().toLowerCase()` approximates full folding but is not conforming and mishandles Cherokee and other special cases. Use ICU through a native binding or service for identifier work, and make the Turkic option explicit. Normalization does not fold case: NFC of `İ` stays `İ` until a separate step changes it. Document the order: NFKC if allowed, case fold, skeleton, allowlist. Changing the order changes the result.

## Grapheme clusters, emoji ZWJ sequences, and flags

Users count grapheme clusters, not code points. A flag emoji is two regional indicators. A family emoji is four emoji joined by three U+200D joiners. A skin-toned emoji is a base plus a modifier. `String.prototype.length` counts UTF-16 code units, spread syntax counts code points, and only `Intl.Segmenter` with `granularity: "grapheme"` follows UAX #29 and counts what a user calls one character.

Normalization and segmentation are separate. NFC and NFD change the number of code points without changing the grapheme: `é` is one code point in NFC, two in NFD, and one grapheme in both. ZWJ sequences are not merged or split by normalization, and variation selectors such as U+FE0F are default-ignorable rather than normalized away.

The [text statistics tool](/tools/text-statistics) reports code units, code points, and graphemes side by side, the fastest way to see why a 280-character limit rejects a post that looks shorter.

```js
const family = "\u{1F468}\u200D\u{1F469}\u200D\u{1F467}\u200D\u{1F466}";
const flag = "\u{1F1FA}\u{1F1F8}";
const cafe = "cafe\u0301";

cafe.length;                                      // 5 UTF-16 code units
cafe.normalize("NFC").length;                     // 4 code units
[...family].length;                               // 7 code points
family.length;                                    // 11 UTF-16 code units

const graphemes = new Intl.Segmenter("en", { granularity: "grapheme" });
[...graphemes.segment(family)].length;            // 1 grapheme cluster
[...graphemes.segment(flag)].length;              // 1 grapheme cluster

family.slice(0, 4);                               // may split a surrogate pair
[...graphemes.segment(family)][0].segment;        // safe complete cluster
```

`slice(0, n)` can cut a surrogate pair or ZWJ sequence, producing a replacement character or a broken family. Truncate by grapheme, then re-normalize if the field requires NFC. For database limits, count graphemes when the product promise is visible characters, but keep a byte or code-point cap as a hard safety limit.

## Confusables, UTS #39, and why normalization is not sanitization

Normalization unifies sequences Unicode declares equivalent, not sequences that merely look alike. Cyrillic `а` U+0430 and Latin `a` U+0061 are different characters, neither canonically nor compatibility equivalent, so NFC and NFKC both preserve the difference. The same holds for Greek `ο` versus Latin `o` and digit `0` versus capital `O`. UTS #39 defines confusables data, skeleton generation, mixed-script detection, and restriction levels used against homograph attacks in usernames and internationalized domain names.

The identifier pipeline is NFKC, case fold, confusable skeleton, then a script allowlist or the Identifier_Status profile. For ASCII-only fields, a regex allowlist is a blunt but effective gate. For Unicode fields, validate with property escapes such as `\p{Script=Latin}` or `\p{ID_Start}` instead of hand-written ranges. The [regex tester](/tools/regex-tester) checks that a pattern rejects mixed-script strings and control characters before production.

Sanitization is a separate policy about allowed characters and constructs. Normalization does not remove a null byte, a bidi override in the U+202A to U+202E range, a zero-width joiner, or markup. A string can be perfectly normalized and still be a phishing payload. Conversely, stripping characters without normalizing can leave two visually identical outputs that compare unequal. Nor does normalization defend against SQL injection, cross-site scripting, or path traversal; those need context-specific encoding, parameterized queries, and path validation.

## Passwords, JavaScript normalize(), and length pitfalls

Password handling needs an explicit, documented policy. A defensible default: accept the password as typed, normalize with NFC at registration and verification, hash with Argon2id, scrypt, or bcrypt, and publish the form. Do not use NFKC: it can map a chosen character to another, shrink the effective alphabet, and surprise users whose password contains a compatibility character. Do not use one form at registration and another at login; that is a silent lockout. RFC 8265 (PRECIS OpaqueString) specifies NFC and replaced the older SASLprep profile that used NFKC; follow its rules for spaces and control characters if you implement a standard.

JavaScript's `String.prototype.normalize(form)` accepts `NFC`, `NFD`, `NFKC`, and `NFKD`, defaults to NFC, and throws `RangeError` otherwise. Three pitfalls matter. `length` counts UTF-16 code units, spread syntax counts code points, and `Intl.Segmenter` counts graphemes; pick the one matching the product requirement. Normalizing before concatenation is not enough, because the join can compose; normalize after joining or at the final boundary. `normalize()` is not a validator: it accepts unpaired surrogates and default-ignorable characters, so code point and script validation must be separate.

`localeCompare` with `sensitivity: "base"` handles case and accent differences for sorting, but it is not normalization and varies by ICU version; do not use it as an identifier equality check. Normalize once at the trust boundary and pass values inward rather than re-normalizing in every layer. For streaming text, normalize complete documents or buffer to a grapheme boundary; normalizing arbitrary byte chunks can split a sequence.

## Verification checklist and pass criteria

Run a golden corpus in CI and treat each item as a release gate.

1. Idempotence: `s.normalize(F).normalize(F) === s.normalize(F)` for each form and corpus string.
2. Canonical pairs: `"e\u0301".normalize("NFC") === "\u00E9".normalize("NFC")`, and a Hangul syllable equals its Jamo decomposition after NFC. Add a Devanagari composition-exclusion case.
3. Compatibility: NFKC maps `"①"` to `"1"`, `"ﬁ"` to `"fi"`, and `"Ａ"` to `"A"`, and no form maps them back.
4. Search parity: golden queries return identical results in NFC and NFD, with asserted recall and false-positive thresholds.
5. Identifier safety: known confusables collide under NFKC_Casefold plus skeleton; a Latin-only field rejects Cyrillic `а`; mixed scripts, bidi controls, and zero-width characters are rejected or escaped.
6. Password parity: an NFC-registered password verifies when the same visible string is typed in NFD; a compatibility-character password behaves as documented.
7. Grapheme limits: family ZWJ, flag, and skin-toned emoji each count one grapheme through `Intl.Segmenter`, and truncation never splits a surrogate pair or ZWJ sequence.
8. Storage: uniqueness is enforced on the normalized column, NFC and NFD lookups return the same row, and an NFD-created file is findable by an NFC path.
9. Version pinning: record Node, ICU, and Unicode versions in CI so a new compatibility mapping appears as a reviewable snapshot diff.

The package passes when every check is green, skeleton duplicates are zero, search-parity misses are zero, and the password migration test produces no lockouts. Calling `normalize("NFC")` on one Latin string is not verification.

One spot check belongs in the runbook. In Node, `node -e "console.log('é'.normalize('NFD').length, [...'👨‍👩‍👧‍👦'].length, [...new Intl.Segmenter('en',{granularity:'grapheme'}).segment('👨‍👩‍👧‍👦')].length)"` should print `2 7 1`.

Normalization is a contract about identity, not a cleanup pass. Apply one documented form per field, keep the original when meaning depends on it, and test the boundaries where strings are joined, truncated, compared, and hashed.

## Frequently asked questions

### Should I store text as NFC or NFD?

NFC is the usual default for general text because it is compact for Latin, Greek, and Cyrillic and matches most input methods. Store one chosen form consistently, keep the original bytes when exact input matters, and normalize incoming data at the write boundary rather than in every read path.

### Does NFKC make text safe?

No. NFKC folds compatibility variants, which helps search keys and identifier skeletons, but it is lossy and does not remove control characters, bidi overrides, markup, or homoglyphs from other scripts. Safety requires a separate validation and sanitization policy.

### Why does 'é' compare unequal to 'e' plus a combining accent?

They are different code point sequences even though they render the same. Only a canonical normalization such as NFC or NFD maps them onto a common sequence. Normalize both operands with the same form before comparing, hashing, or enforcing a unique index.

### Is case folding the same as toLowerCase()?

No. Lowercasing is locale-sensitive and intended for display, while case folding is a Unicode operation for caseless matching. Turkish dotted and dotless i, German sharp s, and Greek sigma produce different results, and JavaScript has no built-in caseFold() method.

### Can I normalize a password with NFKC?

Avoid it. NFKC can map a user's chosen character to a different one and shrink the effective alphabet. Use one documented form, usually NFC, at both registration and verification, and migrate legacy records with a rehash-on-login path instead of changing the form silently.

## References

- [Unicode Standard Annex #15: Unicode Normalization Forms](https://www.unicode.org/reports/tr15/)
- [Unicode Standard Annex #29: Text Segmentation](https://www.unicode.org/reports/tr29/)
- [Unicode Technical Standard #39: Security Mechanisms](https://www.unicode.org/reports/tr39/)
- [MDN: String.prototype.normalize()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)

---

- Canonical: https://www.jsonmind.com/guides/unicode-normalization
- Locale: en
- Published: 2026-11-17
- Updated: 2026-11-17
- Tools: unicode, utf8, text-statistics, regex-tester