Unicode & Formatting

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.

AI Watermark Tools•Published •Updated •10 min read

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:

FormDecompositionRecomposes?Changes meaning?Typical use
NFCCanonicalYesNoStoring and displaying text (the web default)
NFDCanonicalNoNoProcessing accents separately, some file systems
NFKCCompatibilityYesCanSearch keys, usernames, deduplication
NFKDCompatibilityNoCanAccent-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 accent U+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:

InputCode pointAfter NFKC
fi (ligature)U+FB01fi
A (full-width A)U+FF21A
² (superscript two)U+00B22
① (circled digit one)U+24601
½ (vulgar fraction)U+00BD1⁄2
No-break spaceU+00A0normal space (U+0020)
Narrow no-break spaceU+202Fnormal 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 paypal and paypal are 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.

#Unicode#NFC#NFD#NFKC#NFKD#Text Analysis

Related tools

FAQ

Both are canonical forms, so they never change what the text means. NFC composes characters where possible (é is one code point, U+00E9). NFD decomposes them (é becomes e plus the combining accent U+0301). The text looks the same; only the underlying code points differ.