Base64 Encoder & Decoder

Encode text to Base64 and decode it back — Unicode-safe, with a URL-safe variant, byte-level detail and exact error positions.

Result
Waiting for input — conversion happens instantly in your browser.

How Base64 Encoding Works

Base64 turns arbitrary bytes into printable text: every 3 bytes (24 bits) become 4 characters, each character carrying 6 bits looked up in a 64-symbol alphabet — A–Z, a–z, 0–9, + and / (RFC 4648).

Work through “Hi”: the bytes are 72 and 105 — binary 01001000 01101001. Regrouped into 6-bit chunks: 010010 000101 1001 — that is 18, 5 and 36, which the alphabet maps to S, G and k. The input was one byte short of a full group, so one = pads the end: SGk=.

Decoding reverses the lookup. Any character outside the alphabet, padding in the wrong place, or a length that is not a multiple of 4 means the input is not valid Base64 — this converter tells you the exact position instead of failing silently.

Where Base64 Is Used

  • Data URLs — images embedded directly in HTML or CSS, no separate file request.
  • Email attachments — MIME carries binary files through text-only mail infrastructure.
  • Tokens and JWTs — the URL-safe variant travels in URLs and headers without escaping.
  • APIs — binary payloads inside JSON, which only accepts text.

One honest limit: Base64 is not encryption. It is a public, reversible encoding — anyone can decode it in one click. It exists to move binary data through text channels, never to keep secrets.

Base64 vs Hex

Both respell bytes as text. Base64 is the compact one for transport: 33% size overhead versus hex doubling the data (2 characters per byte). Hex stays readable value by value — that is why debugging uses it; see binary vs hexadecimal for the full comparison. For pure bytes-to-text work our text to binary converter shows the raw bits underneath either notation.

Common Mistakes

  • Mistake: treating Base64 as encryption. Correction: it is a public encoding — decoding needs no key. If data must stay secret, encrypt it first, then Base64 the ciphertext if you need text.
  • Mistake: encoding Unicode text byte-blind. JavaScript’s btoa() only accepts Latin-1 and throws on 你 or 👋 — many online tools inherit that bug. Correction: text must become UTF-8 bytes first; this converter does that step, so 你好 correctly becomes 5L2g5aW9.
  • Mistake: mixing standard and URL-safe output. Correction: + and / break URLs — use the URL-safe variant (- and _) for tokens and parameters.

Practice

1. Encode “f” by hand. One byte (102) is 01100110 — two 6-bit groups: 25 and 32 → Z and g, then two padding characters. Answer: Zg==.

2. Why does “Hi” produce SGk= and not SGk? “Hi” is 2 bytes — one short of a 3-byte group, so one = pads the final group to 4 characters. Check both in the converter above.

Base64 FAQ

Is Base64 encryption?

No. Base64 is an encoding, not encryption — anyone can decode it instantly with the public alphabet. It exists to carry binary data through text-only channels, not to keep secrets. Never use it to protect passwords or sensitive data.

What is Base64 used for?

Carrying binary data through text-only systems: images embedded in HTML or CSS as Data URLs, email attachments in MIME, tokens like JWT, and binary payloads in JSON APIs. If a channel only accepts printable text, Base64 is the standard workaround.

Why does Base64 end with = signs?

The = signs are padding. Base64 works in groups of 3 bytes → 4 characters, so when the input is not a multiple of 3 bytes, one or two = characters pad the final group to length 4. “Hi” is 2 bytes, so it becomes SGk= with one padding character.

What is URL-safe Base64?

URL-safe Base64 (Base64URL) swaps the two characters that break URLs: + becomes - and / becomes _, and padding is usually omitted. It is defined in RFC 4648 §5 and is the variant used in JWTs and URL parameters. Toggle URL-safe above to use it.

How much bigger does Base64 make my data?

About 33% bigger: every 3 bytes become 4 characters. That is the price of text safety — hex, by comparison, doubles the size (2 characters per byte). The trade-off is fixed and predictable either way.

Can Base64 handle Chinese text or emoji?

Yes — Base64 encodes bytes, not characters, so any Unicode text works once it is turned into UTF-8 bytes first. This converter does that step correctly (many tools get it wrong): 你好 becomes 5L2g5aW9 and decodes back exactly.