Skip to content

Base64 Encode/Decode

Encode text or decode Base64 strings. Preview Base64-encoded images instantly.

How it works

Base64 converts arbitrary bytes into a 64-character alphabet (A–Z, a–z, 0–9, +, /) so binary data can travel through text-only channels such as JSON, XML, email headers or CSS. Every three input bytes become four output characters, which is why Base64 is about 33% larger than the original and why the output length is always a multiple of four, padded with = when needed.

This tool handles text in both directions and is UTF-8 safe: accents, emoji and non-Latin scripts are encoded through their UTF-8 byte representation before conversion, so café ☕ round-trips exactly instead of being mangled by the legacy btoa Latin-1 limitation.

You can also drop or select a file. The browser reads it locally as a data URL, so images, PDFs or any other binary content become a copyable Base64 string without ever leaving your machine. When you decode a value that looks like a PNG, JPEG or GIF image, an inline preview renders automatically — a quick way to verify a data:image URI before embedding it.

Decoding is strict: invalid alphabet characters or truncated input raise an explicit error instead of silently producing garbage. That makes the tool useful for checking whether a mysterious string really is Base64 before you build logic around it.

Worked example

Encode Hello, World!. The twelve characters become sixteen Base64 characters with no padding, because twelve bytes divide evenly by three.

Input bytesGrouped asBase64 output
Hel3 bytes → 4 charsSGVs
lo,3 bytes → 4 charsbG8s
Wo3 bytes → 4 charsIFdv
rld3 bytes → 4 charscmxk
  1. Choose a direction: Paste plain text to encode, or a Base64 value to decode.
  2. Run the conversion: Use Encode or Decode; errors are reported explicitly instead of failing silently.
  3. Check images visually: If the value is a PNG, JPEG or GIF, confirm it in the automatic preview.
  4. Copy or encode a file: Copy the output, or drop a file to get its data URL for embedding.

Concatenated, the result is SGVsbG8sIFdvcmxk. Decoding reverses the mapping exactly. A five-byte input such as Hello would end with one = padding character, and four-byte input with two.

Common errors and edge cases

  • UTF-8 mojibake. If decoded text shows é instead of é, the original was encoded as raw Latin-1. This tool encodes via UTF-8, which fixes new data but cannot repair already-corrupted strings.
  • Missing padding. Some systems strip trailing =. Most decoders accept it, but if yours complains, re-add = until the length is a multiple of four.
  • Base64URL vs Base64. URLs and JWTs use - and _ instead of + and /. Swap the alphabets before decoding JWT segments.
  • Embedded whitespace. Line breaks inside a pasted value are a common cause of decode errors; remove them or let the tool trim the input.
  • Not encryption. Base64 is reversible by anyone. Never use it to hide passwords, keys or personal data.

Code equivalents

Base64 is built into every common runtime, so you can reproduce the conversion in scripts without dependencies.

LanguageExample
JavaScript (UTF-8 safe)btoa(unescape(encodeURIComponent(text))) encodes; decodeURIComponent(escape(atob(b64))) decodes.
Python 3base64.b64encode(text.encode('utf-8')) encodes; base64.b64decode(data).decode('utf-8') decodes.
Shellprintf 'Hello' | base64 encodes; printf 'SGVsbG8=' | base64 -d decodes.

Frequently asked questions

Is Base64 a form of encryption?

No. It is an encoding with a public, fixed alphabet. Anyone can decode it instantly, so it provides confidentiality for nothing.

Why is my Base64 output longer than the input?

Base64 maps three bytes to four characters, so output is about 33% larger, plus up to two padding characters. That overhead is the price of a text-safe alphabet.

Can I encode an image or PDF?

Yes. Drop or select the file and the browser reads it locally as a data URL. Image results also render an inline preview after encoding or decoding.

What is the difference between Base64 and Base64URL?

Base64URL replaces + and / with - and _ and usually omits padding so the value is safe in URLs and filenames. JWTs use this variant.

Why does decoding fail on a string I copied from a log?

The usual causes are truncated output, embedded line breaks, or a Base64URL alphabet. Clean the whitespace first, then check for - and _ characters.

Privacy note

All processing happens in your browser. The values you enter never leave your device and are never transmitted to ToolPlex.