Skip to content
All posts
8 min read(updated October 28, 2026)

Character Sets Explained: How Encoding Detection Works and Why It Matters for Base64

Base64 moves bytes, but characters become bytes through a character set. This guide explains ASCII, Unicode, UTF-8, legacy code pages, CJK and EBCDIC, how auto-detection works, and why picking the wrong charset turns readable text into mojibake.

  • guide
  • unicode
  • charsets
  • fundamentals

Base64 is honest about one thing: it moves bytes. It does not know what a “character” is, it does not understand language, and it never looks at letters. What Base64 sees is a sequence of 8-bit values — 0x41, 0xC3, 0x89, 0x00 — and nothing more. The step that turns human text into those bytes, and back again, belongs to something else entirely: a character set (more precisely, a character encoding). When you paste café into an encoder and get Y2Fmw6k= back, two different systems just cooperated silently. One turned é into bytes (C3 A9 in UTF-8), and Base64 then wrapped those bytes into printable text. Change the first system — read C3 A9 as Latin-1 instead of UTF-8 — and you get café. The Base64 layer never made a mistake; the character set did.

This guide explains how character sets work, why Base64 output can look perfect while the decoded text is garbage, how auto-detection guesses the right charset, and which encodings you are most likely to meet in practice.

What a character set actually is

Computers store numbers, not glyphs. The letter A is not stored as a drawn shape; it is stored as a number — 65 in nearly every system in use today. A character set is the dictionary that maps numbers to characters and back:

  • ASCII (1963): 128 characters, numbers 0–127. Covers English letters, digits, basic punctuation, and control characters like newline and tab. Everything above 127 is undefined.
  • Extended ASCII / single-byte encodings: Use the full byte (0–255) by assigning characters to the high half (128–255). There are dozens of these, and they disagree violently about which character lives at 0xE9.
  • Unicode (1991–present): One unified map aiming to cover every character in every language, plus symbols, emoji, and historic scripts. Each entry is a code point written as U+XXXX.
  • UTF-8: The dominant way to store Unicode as bytes. ASCII characters stay one byte; everything else uses two to four bytes. It is self-checking, backward-compatible with ASCII, and the encoding of the modern web.

The critical insight: Base64 operates after this step is already finished. It receives bytes. Whether those bytes came from UTF-8, Windows-1252, or EBCDIC is invisible to Base64. That is why two people can Base64-encode the same-looking word and get completely different strings — their computers used different character sets to produce the bytes.

The families you will actually meet

Western European

The most common legacy encodings in Western Europe and the Americas:

Charset What it is Where you see it
ISO-8859-1 (Latin-1) 256 characters, Western European Old web pages, email headers, legacy databases
Windows-1252 Superset of Latin-1 with smart quotes, €, en/em dashes Windows text files, copy-paste from Word, old CSV exports
Mac OS Roman Classic Macintosh encoding Very old Mac documents

Latin-1 and Windows-1252 agree on most characters but diverge in the 0x80–0x9F block: Latin-1 treats those as control codes, while Windows-1252 puts €, ™, curly quotes, and dashes there. A UTF-8 byte sequence for a curly apostrophe (E2 80 99) read as Windows-1252 becomes ’ — the most recognizable mojibake of the last twenty years.

Central and Eastern European, Cyrillic, Greek, Turkish

These regions needed more than 256 characters could not easily provide, so each got its own set of single-byte code pages:

  • ISO-8859-2 (Central European), ISO-8859-5 (Cyrillic), ISO-8859-7 (Greek), ISO-8859-9 (Turkish)
  • Windows-1250, Windows-1251, Windows-1253, Windows-1254, Windows-1257 (the Windows equivalents)
  • KOI8-R and KOI8-U (Russian and Ukrainian, with a different letter order than Windows-1251)

A document encoded in Windows-1251 and read as ISO-8859-5 produces plausible-looking but wrong Cyrillic text. Decoders that score by letter frequency (Russian о, е, а dominate real text) can tell the difference, but short strings defeat every heuristic.

CJK: Chinese, Japanese, Korean

East Asian writing uses thousands of characters, far more than one byte can address. These encodings use multi-byte sequences:

  • Shift_JIS, EUC-JP, ISO-2022-JP (Japanese)
  • GBK, GB18030, EUC-CN (Simplified Chinese)
  • Big5, CP950, EUC-TW (Traditional Chinese)
  • EUC-KR, CP949, ISO-2022-KR (Korean)
  • HZ-GB-2312 (a 7-bit Chinese encoding for old email systems)

The dangerous property of CJK sets: nearly every byte sequence maps somewhere, so a wrong-charset decode rarely produces replacement characters (�). It produces plausible-looking hanzi or kana. Nothing looks broken until you read it.

EBCDIC

IBM mainframes never adopted ASCII. EBCDIC encodes letters in scattered ranges (e.g., B is 0xC2), places the space at 0x40 (which ASCII reads as @), and has no lowercase/uppercase relationship you can compute with simple math. Reading an EBCDIC feed with an ASCII decoder turns spaces into @ and produces Â-prefixed garbage wherever EBCDIC lead bytes look like UTF-8 lead bytes.

Unicode’s companions

UTF-16 and UTF-32 store Unicode code points as 2- or 4-byte units. Windows APIs and many file formats use UTF-16LE, which looks like alternating ASCII bytes and NUL bytes (63 00 61 00 66 00 for caf). A UTF-8 decoder chokes on those NULs. UTF-16 files often begin with a BOM (FF FE for little-endian, FE FF for big-endian), which is the most reliable signal a detector can get.

How auto-detection works

A good decoder does not ask you to guess. It runs detection in layers, from certain to statistical:

  1. Byte-order marks. EF BB BF means UTF-8 with BOM. FF FE means UTF-16LE. FE FF means UTF-16BE. Certain by design.
  2. Structural validity. Valid UTF-8 is self-checking: multi-byte sequences follow strict bit patterns. Random bytes almost never form valid long UTF-8 runs. If the bytes pass, UTF-8 is almost certainly right.
  3. Escape sequences. ISO-2022-JP embeds ESC ( B and ESC $ B switches. When present, the encoding is definitive.
  4. EBCDIC fingerprints. Almost no 0x20 space bytes, abundance of 0x40, and distinctive letter ranges — instantly recognizable.
  5. Frequency analysis. Real language has a letter-frequency fingerprint: Russian text is dominated by о, е, а, и; English by e, t, a. Comparing decoded text against these tables separates KOI8-R from Windows-1251, or Czech from Polish.

Layer 5 is probabilistic. On a two-character input, no detector on earth can distinguish Latin-1 from Windows-1252. Give it a sentence, and it can.

Layer 4 and below are deterministic; anything above them is a guess. That is why a professional tool tells you why it picked a charset, and lets you override it when you know the source.

Why charset decides whether Base64 output is useful

Here is the same word through two paths:

"café" ──(UTF-8)──> 63 61 66 C3 A9 ──(Base64)──> Y2Fmw6k=
"café" ──(Latin-1)──> 63 61 66 E9 ──(Base64)──> Y2FmwQ==

Both Base64 strings are valid. Both decode perfectly back to their original bytes. But hand Y2FmwQ== to a UTF-8 reader and E9 is not a valid UTF-8 continuation byte — you get caf� or worse. Hand Y2Fmw6k= to a Latin-1 reader and C3 A9 becomes é.

The Base64 layer did nothing wrong in either case. The charset layer decided what the bytes mean, and Base64 simply preserved them. This is why “it decoded fine” is not the same as “it decoded right”: a decoder can emit bytes without error while interpreting them as the wrong script.

A worked debugging checklist

When decoded text looks wrong, work through these questions in order:

  1. Is it double-encoded? If the decode result is itself Base64-shaped ([A-Za-z0-9+/=]+), decode again. Double-encoding happens in mail gateways, form pipelines, and code that treats byte arrays as text mid-pipeline.
  2. Is there a Data URL prefix? Strip data:…;base64, before decoding anything after the comma.
  3. Which alphabet? - or _ means URL-safe Base64; a missing = suffix means stripped padding. Use a decoder that accepts either alphabet automatically.
  4. Is this a charset mismatch, not a Base64 error? Ask what produced the bytes: Windows APIs (UTF-16LE), pre-2000 exports (Windows-1252), mainframe feeds (EBCDIC), modern toolchains (UTF-8).
  5. Is the input structurally broken? A = in the middle of the string, or a total length where length mod 4 === 1, means the data was truncated or was never Base64.

Practical advice

  • Default to UTF-8. For anything new, UTF-8 is the correct choice. It is universal, self-checking, and what every modern toolchain expects.
  • Pin legacy sources explicitly. A 1998 export, an IBM mainframe feed, or a Windows-1252 CSV deserves an explicit charset, not a guess. Never let auto-detection silently choose for data you know the provenance of.
  • Decode to bytes first, then to text. Look at the raw bytes (00 between letters ⇒ UTF-16; high bytes in pairs ⇒ UTF-8; almost no 0x20 ⇒ EBCDIC) before you commit to an interpretation.
  • Never use Base64 for secrecy. It is an encoding, not encryption. Anyone can decode it instantly with no key.

Base64 moves bytes faithfully. Character sets decide what those bytes mean. Get the charset right, and everything else follows.


Try it: encode text in one charset, decode it in another, and watch the difference for yourself with the Base64 encoder and Base64 decoder, which together support 91 encode and 92 decode options including every major legacy and CJK character set.

Try it yourself — right now

Both tools run 100% in your browser. Nothing you type or drop is ever uploaded.

Related posts

esc

Tools

Pages

↑↓ navigate↵ open⌘K

Keyboard shortcuts

Same shortcuts everywhere — ⌘ on macOS, Ctrl on Windows and Linux.