What Is Mojibake?
Mojibake is garbled text produced when bytes encoded with one character encoding are decoded using the wrong encoding.
On this page
Mojibake at a glance
| Concept | Explanation |
|---|---|
| Mojibake | Garbled text caused by an encoding or decoding mismatch |
| Common example | café becomes café |
| Typical cause | UTF-8 bytes decoded as Windows-1252 or ISO-8859-1 |
| Repairable? | Often, if the original bytes or reversible corruption remain |
| Permanent loss possible? | Yes, especially after replacement characters or lossy conversions |
| Best first step | Preserve the original data before attempting repair |
Mojibake is usually not a font problem. It is a mismatch between the bytes that were stored and the encoding used to interpret them.
What does mojibake mean?
Mojibake refers to unreadable or incorrectly rendered text. It commonly appears as accented Latin characters, strange punctuation or repeated symbols. The visible output is often valid text under the wrong interpretation, which is why it can be copied, saved and corrupted again. Mojibake is different from missing-glyph boxes, different from intentional replacement characters and different from damaged storage. It is often reversible when the mistaken decoding path is known.
Correct: café
Mojibake: café
Correct: It’s working
Mojibake: It’s working
Correct: “Hello”
Mojibake: “Hello�Start with Mojibake Repair and inspect suspicious characters with the Unicode Character Inspector.
Encoding and decoding explained
Encoding
Encoding converts Unicode text into bytes using a character encoding.
é
Unicode code point: U+00E9
UTF-8 bytes: C3 A9Decoding
Decoding converts bytes back into Unicode text according to an encoding. Encoding and decoding must agree because a byte sequence has no universal textual meaning without an encoding.
Correct path:
é → encode as UTF-8 → C3 A9 → decode as UTF-8 → é
Incorrect path:
é → encode as UTF-8 → C3 A9 → decode as Windows-1252 → éUnicode code points and UTF-8 bytes are not the same thing. Re-decoding already decoded text can create additional corruption. Read Unicode vs UTF-8 and UTF-8 vs UTF-16, then test bytes with UTF-8 Encoder and Decoder.
Why does é appear instead of é?
The character é is Unicode code point U+00E9. In UTF-8, it is stored as two bytes: C3 A9. If those bytes are interpreted as Windows-1252, C3 maps to à and A9 maps to ©, producing é after the visible text is rendered. The displayed second character can depend on the exact single-byte encoding and subsequent processing.
| Original | UTF-8 bytes | Common mojibake |
|---|---|---|
| é | C3 A9 | é |
| ñ | C3 B1 | ñ |
| ü | C3 BC | ü |
| £ | C2 A3 | £ |
| © | C2 A9 | © |
The leading  often appears when UTF-8 bytes beginning with C2, including non-breaking spaces and symbols, are decoded as a single-byte encoding.
Common mojibake patterns
| Mojibake sequence | Likely intended text | Common cause |
|---|---|---|
é | é | UTF-8 decoded as Windows-1252 |
ñ | ñ | UTF-8 decoded as Windows-1252 |
’ | ’ | UTF-8 smart apostrophe decoded incorrectly |
“ | “ | UTF-8 opening smart quote decoded incorrectly |
â€� | ” | UTF-8 closing smart quote decoded incorrectly |
– | – | UTF-8 en dash decoded incorrectly |
— | — | UTF-8 em dash decoded incorrectly |
… | … | UTF-8 ellipsis decoded incorrectly |
 | Non-breaking space | UTF-8 decoded as a single-byte encoding |
 | UTF-8 BOM displayed as text | BOM bytes decoded as visible characters |
These patterns are clues, not proof. Do not promise an exact repair only from appearance.
Interactive mojibake analyzer
This local analyzer models likely encode/decode transformations, ranks repair candidates and warns when corruption is uncertain or lossy. It preserves the original input and does not send text to the backend.
Mojibake analyzer
Model likely wrong-decoding paths and compare repair candidates.
Limit: 2,000 UTF-16 code units. The analyzer keeps input local.
| Candidate | Likely path | Confidence | Proposed text | Changed | Code points |
|---|
Windows-1252 vs ISO-8859-1 confusion
Windows-1252 and ISO-8859-1 overlap substantially. Windows-1252 assigns printable punctuation where ISO-8859-1 defines control characters, and many systems historically labeled Windows-1252 data as ISO-8859-1. Smart quotes and dashes often point toward Windows-1252, but exact repair still requires knowing the actual byte interpretation.
’
U+2019
UTF-8 bytes: E2 80 99
Misdecoded as Windows-1252: ’The first byte E2 becomes â, and the following bytes become Windows-1252 punctuation/control-derived characters.
What is double encoding?
Double encoding happens when text is encoded into bytes, decoded incorrectly into mojibake, and then the mojibake text is encoded again. Repeated patterns such as àcan indicate an extra corruption layer.
é
→ é
→ é| Stage | Display |
|---|---|
| Original | é |
| First corruption | é |
| Double-encoded corruption | é |
Each repair layer must be reversed in the correct order.
What does the replacement character mean?
� is U+FFFD REPLACEMENT CHARACTER. It is inserted when a decoder encounters invalid or unrepresentable input. It often indicates that original byte information was lost. It is not the same as mojibake such as é, and once bytes are replaced with U+FFFD, exact recovery may be impossible without the original file, database backup or raw network payload.
caf�The missing original byte sequence cannot generally be inferred with certainty. Validate raw bytes with the UTF-8 Validator and inspect U+FFFD with the Unicode Character Inspector.
Mojibake vs missing glyphs
Mojibake displays wrong decoded characters. Missing glyphs happen when the correct code point exists but the font cannot draw it, often showing a box or tofu symbol. Changing fonts may fix missing glyphs, but it usually does not fix mojibake.
| Problem | Underlying text | Typical display | Likely fix |
|---|---|---|---|
| Mojibake | Wrong decoded code points | é | Correct encoding interpretation |
| Missing glyph | Correct code point | □ or blank box | Use a font with coverage |
| Replacement character | Invalid input replaced | � | Recover original bytes if possible |
Mojibake vs Unicode normalization problems
Mojibake is primarily an encoding or decoding problem. Normalization concerns equivalent code-point sequences, such as NFC and NFD. Normalization does not usually repair é, and mojibake repair does not automatically normalize text. Both issues can occur in the same pipeline.
Mojibake:
é → é
Normalization difference:
U+00E9 vs U+0065 U+0301Read Unicode Normalization Explained, NFC vs NFD or use Unicode Normalizer.
Can mojibake always be fixed?
Reversible corruption
The original byte information is still represented through a reversible wrong decode. café may often be repairable to café.
Ambiguous corruption
Several original strings or encoding paths may be plausible. A good tool should show alternatives.
Irreversible corruption
Original bytes may have been replaced with U+FFFD, dropped, converted through a lossy character set, truncated, manually edited, normalized through an irreversible compatibility step or re-encoded through multiple unknown systems. For a repair workflow, read How to Fix Broken UTF-8 Text.
How to identify the original encoding
- Preserve the original file or byte stream.
- Check metadata and protocol declarations.
- Inspect a BOM.
- Validate as UTF-8.
- Look for characteristic byte patterns.
- Review the source system and language.
- Compare likely encodings.
- Use encoding detection as a probability, not certainty.
- Test a sample before converting a whole dataset.
- Verify repaired text with a native speaker or authoritative source when possible.
File extensions alone do not identify encoding. Use Character Encoding Detector, UTF-8 Validator and UTF-8 Encoder and Decoder.
How to fix mojibake safely
- Make a backup.
- Preserve original bytes.
- Identify the visible corruption.
- Infer the likely mistaken decoding.
- Re-encode the mojibake text using the mistaken encoding.
- Decode those bytes using the intended encoding.
- Compare candidate repairs.
- Validate characters and language.
- Test on a small sample.
- Write repaired output to a new file or field.
- Keep an audit log.
- Avoid repeatedly repairing already-correct values.
Current text: café
Encode as Windows-1252 bytes
Decode resulting bytes as UTF-8
Result: caféThis procedure works only when the corruption path matches.
Mojibake in web pages
Common causes include missing or incorrect <meta charset>, wrong HTTP Content-Type, disagreement between server and HTML declarations, database connection encoding mismatch, template files saved in another encoding, text decoded twice, proxy transformation and incorrect form-submission handling.
<meta charset="utf-8">Content-Type: text/html; charset=utf-8The charset declaration should appear early in HTML. Inspect response headers, raw bytes, template encoding, database connections, frontend conversions and reverse-proxy behavior.
Mojibake in databases
Application connection encoding may differ from table encoding. Data may be inserted as bytes under the wrong character set, or it may already be corrupted before insertion. Changing a column declaration does not automatically repair stored bytes. Export and import tools may use different encodings, collation does not repair mojibake, and double conversion can worsen corruption.
original_value
repaired_value
repair_status
repair_methodFor production migrations, sample affected rows, identify patterns, create reversible migrations, record backups, verify counts and hashes, and avoid global replacement without validation.
Mojibake in CSV and spreadsheet files
CSV does not reliably declare encoding by itself. Spreadsheet applications may guess. UTF-8 without BOM may be misdetected by older workflows, while a UTF-8 BOM can help some spreadsheets but affect other tools. Regional settings can affect delimiters independently of encoding. Export and import settings must agree.
Export explicitly as UTF-8, preserve the original file, validate before import, test accented and non-Latin sample values, and avoid opening and resaving through unknown encodings.
Mojibake in APIs and JSON
JSON text uses Unicode characters and is commonly transported as UTF-8. HTTP headers and actual payload bytes must agree. Manual encode/decode calls can corrupt already-decoded strings. Base64 is not a character encoding, escaped JSON such as \u00E9 is not mojibake, logging systems may introduce encoding problems, and signatures or hashes depend on exact bytes.
Content-Type: application/jsonUnicode string
→ serialize JSON
→ encode payload as UTF-8
→ transmit bytes
→ decode once
→ parse JSONMojibake in copied PDF text
PDF text extraction may produce incorrect character mappings. Embedded fonts may map glyphs to unexpected values, visual glyph order may differ from logical text order, and missing spaces or incorrect ligatures are not always classic mojibake. OCR errors are different from encoding errors, and a generic encoding repair may not fix a bad PDF character map.
Try Clean Copied PDF Text and inspect output with the Unicode Character Inspector.
Mojibake in JavaScript
JavaScript strings are already decoded Unicode text. TextEncoder encodes strings as UTF-8, and TextDecoder decodes byte arrays. Using the wrong decoder creates mojibake. Deprecated escape() and unescape() hacks, including decodeURIComponent(escape(text)), are unsafe and unreliable.
const original = "café";
const bytes = new TextEncoder().encode(original);
const decoded = new TextDecoder("utf-8", {
fatal: true,
}).decode(bytes);
console.log(decoded);function decodeUtf8(bytes) {
return new TextDecoder("utf-8", {
fatal: true,
}).decode(bytes);
}fatal: true reports invalid sequences. Without it, replacement characters may be inserted. Browser support for legacy labels should be tested.
Mojibake in Python
Python str contains Unicode text and bytes contains encoded bytes. .encode() converts text to bytes; .decode() converts bytes to text.
original = "café"
encoded = original.encode("utf-8")
decoded = encoded.decode("utf-8")
print(decoded)original = "café"
utf8_bytes = original.encode("utf-8")
mojibake = utf8_bytes.decode("windows-1252")
repaired = mojibake.encode("windows-1252").decode("utf-8")
print(mojibake)
print(repaired)def repair_utf8_as_windows_1252(text: str) -> str:
try:
raw_bytes = text.encode("windows-1252")
return raw_bytes.decode("utf-8")
except (UnicodeEncodeError, UnicodeDecodeError) as error:
raise ValueError(
"Text does not match the expected mojibake pattern."
) from errorDo not apply this to every string. Preserve original data, use strict errors and test candidate encodings.
Mojibake in PHP
PHP strings are byte sequences. Encoding-aware functions must be used deliberately, and applying a conversion in the wrong direction can create mojibake. Input must be validated before bulk repair.
function repairUtf8DecodedAsWindows1252(
string $text
): string {
$bytes = mb_convert_encoding(
$text,
"Windows-1252",
"UTF-8"
);
return mb_convert_encoding(
$bytes,
"UTF-8",
"Windows-1252"
);
}if (!mb_check_encoding($value, "UTF-8")) {
throw new InvalidArgumentException(
"Input is not valid UTF-8."
);
}mbstring is required, labels may differ by runtime, bulk repair must be tested on representative samples, and PHP strings do not automatically track their encoding.
Common mojibake repair mistakes
Applying replacements such as é → é
Replacement tables miss many sequences and can alter legitimate text.
Repairing every string automatically
Correct text can be damaged.
Running the same repair twice
This can reverse correct text or create new corruption.
Discarding the original bytes
Exact recovery may become impossible.
Treating encoding detection as certainty
Detection is heuristic.
Changing the database charset and assuming data is repaired
Stored bytes may remain corrupted.
Ignoring double encoding
One repair pass may not be enough.
Confusing mojibake with normalization
They require different fixes.
Confusing mojibake with OCR errors
PDF and image extraction may produce unrelated errors.
Silently replacing invalid bytes
Replacement characters can destroy evidence needed for repair.
Using lossy encode/decode error modes
Ignoring invalid bytes may hide corruption.
Repairing signed or hashed data
Changing bytes invalidates signatures and hashes.
How to prevent mojibake
Files
Save source and data files as UTF-8, declare encoding explicitly, validate imports and test non-ASCII samples.
Web
Send the correct HTTP charset, include <meta charset="utf-8">, and keep templates and source files in UTF-8.
Databases
Use full-Unicode configuration, configure connections consistently, avoid unnecessary conversions, and test migration and backup tools.
APIs
Encode payloads once, decode payloads once, define byte encoding and validate raw payloads when required.
Applications
Separate text from bytes, avoid ambiguous conversion helpers, log encoding metadata rather than sensitive text, preserve originals during repair and add Unicode regression tests.
Practical mojibake debugging workflow
- Preserve the original source.
- Determine whether you have bytes or already-decoded text.
- Check the declared encoding.
- Validate raw bytes as UTF-8.
- Inspect suspicious characters and code points.
- Identify common mojibake signatures.
- Test likely decoding paths.
- Rank candidate repairs.
- Compare repaired text with expected language.
- Check for double encoding.
- Write repaired output separately.
- Add regression tests before deploying a bulk fix.
Use Mojibake Repair, UTF-8 Validator, Character Encoding Detector, Unicode Character Inspector and Unicode Text Compare.
Try these UnicodeNow tools
These tools help identify bad byte paths, validate UTF-8, inspect code points and compare repaired text.
Mojibake Repair
Try common repairs for text decoded with the wrong encoding.
UTF-8 Validator
Validate hexadecimal byte sequences as UTF-8.
Character Encoding Detector
Compare likely text encodings from raw bytes or byte-like input.
Unicode Character Inspector
Inspect each Unicode character, encoding, category, script and normalization form.
UTF-8 Encoder and Decoder
Convert text to UTF-8 bytes and validate byte sequences.
Unicode Text Compare
Compare strings exactly and after Unicode normalization.
Unicode Text Cleaner
Normalize, trim and clean problematic Unicode text safely.
Invisible Character Detector
Find zero-width, control, variation, private-use and spacing characters.
Text to Hex
Convert UTF-8 text bytes into hexadecimal values.
For hex-level inspection, also use Hex to Text.
Frequently asked questions
What is mojibake?
Garbled text caused by decoding bytes with the wrong character encoding.
Why does é become é?
Its UTF-8 bytes were likely interpreted as a single-byte encoding such as Windows-1252.
What causes ’?
It commonly represents a UTF-8 smart apostrophe decoded incorrectly.
What does  mean in broken text?
It often appears when UTF-8 bytes for symbols or non-breaking spaces are decoded as a single-byte encoding.
Can mojibake be repaired?
Often, when the wrong decoding path is reversible and original information remains.
Can the replacement character � be repaired?
Not reliably from the replacement character alone, because original bytes may have been lost.
Is mojibake a font problem?
Usually no. Missing glyphs and encoding errors are different problems.
Is mojibake the same as broken UTF-8?
Broken UTF-8 is one possible cause, but mojibake can involve many encoding mismatches.
Is mojibake the same as Unicode normalization?
No. Normalization handles equivalent code-point sequences; mojibake is an encoding or decoding problem.
Can opening a CSV in a spreadsheet cause mojibake?
Yes, when the application guesses or applies the wrong encoding.
Can changing a database charset fix mojibake?
Not automatically. Existing data may need a controlled repair.
Why does mojibake sometimes become worse after saving?
The corrupted text may be encoded again, creating double encoding.
Should I use search and replace to fix mojibake?
Not as a general solution. Reversing the actual encoding path is safer.
How do I prevent mojibake?
Use explicit encodings, validate boundaries and avoid unnecessary repeated conversions.