Replacement Character in Unicode (U+FFFD): What It Means and How to Find It

What the Unicode replacement character U+FFFD is, why it appears in UTF-8 text, and how to detect it and tell lost data from recoverable bytes.

If your text shows a black diamond with a question mark (�) where a letter, accent or symbol should be, you are looking at the Unicode replacement character. This guide explains what it is, why it appears in UTF-8 text, and how to confirm whether the original content can still be recovered.

What the replacement character is

The replacement character is code point U+FFFD, officially named REPLACEMENT CHARACTER, in the Specials block of Unicode. Its job is to stand in for data that a program could not interpret as a valid character. Most fonts draw it as a dark diamond containing a white question mark, though the exact look depends on the font.

In practice, U+FFFD is usually inserted by a decoder: the part of a program that turns raw bytes into characters. When the decoder meets a byte sequence that is invalid in the encoding it was told to use, it can either stop with an error or substitute U+FFFD and keep going. Many tools choose the second option by default, so the text loads but the unreadable parts are marked with �.

What it does to your text

  • Input: a sequence of bytes that is supposed to be text in some encoding, such as UTF-8.
  • Trigger: one or more bytes that do not form a valid character in that encoding.
  • Output: readable text in which each unreadable stretch is replaced by U+FFFD.
  • Side effect: the original bytes at that position are not kept in the decoded text. If that text is saved, the information is gone from the saved copy.

How many replacement characters appear for one damaged stretch can vary between implementations. Unicode describes a recommended practice for this, but you should not rely on the count to reconstruct what the original bytes were.

The replacement character in UTF-8

U+FFFD is itself a normal, valid character. In UTF-8 it is stored as three bytes: EF BF BD. In UTF-16 it is the single code unit FFFD. In HTML you can write it as � or �.

Common reasons it shows up in UTF-8 text:

  • A file saved in a legacy encoding (for example Windows-1252 or Latin-1) is opened as UTF-8, so accented letters become invalid byte sequences.
  • A multi-byte UTF-8 character was cut in half, for example by truncating a string by byte count or splitting a stream at an arbitrary byte.
  • Binary data or corrupted bytes were mixed into a text field.
  • An earlier step in a pipeline already replaced bad bytes with U+FFFD and saved the result, so every later tool shows it too.

Don't confuse it with similar-looking problems

What you see | What it usually is | Is the original recoverable from this text?
� (diamond with question mark) | U+FFFD inserted by a decoder | Not from the decoded text; possibly from the original bytes
Empty box or box with hex digits (often called tofu) | A valid character the current font cannot draw | Yes, the character is intact; change the font
ïż½ or � | The bytes EF BF BD (a stored U+FFFD) read as Windows-1252 or Latin-1 | No; the underlying character is already U+FFFD
é instead of é | UTF-8 text decoded as a single-byte encoding (mojibake) | Often yes, by re-decoding the bytes correctly

Step by step: recognize it and check whether data is lost

The key question is whether U+FFFD is actually stored in the file, or whether your viewer is inserting it on the fly because the file is in a different encoding. The steps below answer that.

Step 1: Confirm the character is U+FFFD

Copy the suspicious symbol into a Unicode inspector or character-info tool, or check it in code. If it reports U+FFFD REPLACEMENT CHARACTER, continue. If it reports a different code point, you are dealing with a different issue, such as a missing glyph.

Step 2: Search the raw bytes for EF BF BD

Search the file as bytes, not as decoded text, so the viewer cannot insert its own replacements. Example command for a bash shell (illustrative; adjust the file name):

LC_ALL=C grep -n $'\xef\xbf\xbd' input.txt

If this prints lines, the file really contains U+FFFD. The original characters at those positions are not recoverable from this file; you need an earlier copy or the original source.

Step 3: Check whether the file is valid UTF-8

If Step 2 finds nothing but you still see � on screen, the file probably contains bytes that are not valid UTF-8. This illustrative Python snippet counts stored replacement characters and reports where strict UTF-8 decoding first fails:

with open("input.txt", "rb") as f:
    data = f.read()

print("stored U+FFFD:", data.count(b"\xef\xbf\xbd"))

try:
    data.decode("utf-8")
    print("valid UTF-8")
except UnicodeDecodeError as e:
    print("invalid byte at offset", e.start, data[e.start:e.start + 4])

An invalid-byte result is good news: the original bytes are still in the file. The text was simply decoded with the wrong encoding.

Step 4: Re-decode with the correct encoding

Open or convert the file using the encoding it was really written in, then save it as UTF-8. Example with iconv, assuming the source is Windows-1252 (an assumption you must verify for your file):

iconv -f WINDOWS-1252 -t UTF-8 input.txt > output.txt

Work on a copy and keep the original untouched. A wrong guess about the source encoding produces different garbled text rather than an error, so inspect the result before replacing anything.

Step 5: Verify the result

  • Run the byte search from Step 2 on the output; it should find no EF BF BD sequences unless the source genuinely contained U+FFFD.
  • Run the strict decode check from Step 3 on the output; it should report valid UTF-8.
  • Spot-check lines that previously showed �, especially accented letters, currency signs and quotation marks, against a trusted copy of the content.

Preventing new replacement characters

Many decoding functions replace bad bytes silently unless told otherwise. In Python, decoding with errors="replace" produces U+FFFD, while the default strict mode raises an error instead. In JavaScript, TextDecoder replaces by default and throws only when created with the fatal option. Using the strict or fatal mode during imports and conversions makes problems visible at the point they happen, before damaged text is saved.

Also avoid cutting UTF-8 strings by byte length; cut by character instead, so multi-byte characters are never split.

Limits of this guide

No tool-specific documentation or test data was supplied for this article, so it relies on general Unicode and encoding behavior. The commands and code above are illustrative examples, not verified output from your system; exact behavior can differ by tool version, locale and platform. Identifying the original encoding of a legacy file is not covered here and may require knowing where the file came from.