Skip to content
MtrXTools

Base64 encode / decode

Encode text or a file to base64, base64url or a data: URI, and decode base64 back to text or a downloadable file, with the file type recognised and images previewed. Unicode is handled as UTF-8. Runs in your browser.

What it does

  • Encodes text as UTF-8, so accented letters, other alphabets and emoji survive (plain btoa() fails on them).
  • Encodes a file to base64 and to a ready-to-use data: URI for CSS or HTML.
  • Decodes standard base64, the URL-safe base64url alphabet (- and _, used in JWTs) and data: URIs, with or without padding and line breaks.
  • Recognises what decoded binary is (PNG, JPEG, GIF, WebP, PDF, ZIP, gzip or DER certificate data), previews images, and lets you download the file.
  • Explains why invalid input won't decode: a character outside the alphabet, padding in the middle, mixed alphabets, or a length that means the text was cut off.

Base64 is an encoding, not encryption

Base64 turns bytes into 64 printable characters so binary data can travel through text-only channels: email attachments (MIME), JSON and XML fields, HTTP Basic authentication headers, Kubernetes secrets and data: URIs. Anyone can decode it, so it hides nothing: a Kubernetes secret or a Basic auth header in base64 is as readable as plain text.

Questions

What is the difference between base64 and base64url?
base64url (RFC 4648 section 5) replaces + and / with - and _, and usually drops the = padding, so the result is safe in URLs and file names. JWTs, WebAuthn and many APIs use it. The decoder accepts both.
Why is the output a third larger than the input?
Base64 turns every 3 bytes into 4 characters, so encoded data is about 33% larger, plus line breaks if it is wrapped at 76 characters for email.
Why does decoding give strange characters?
The data was binary (an image, a compressed file, a certificate) or text in an encoding other than UTF-8. The tool shows binary as a hex dump with the file type it recognises and a download button.