formaterTools Logo Formater Tools

Base64 Encode / Decode

Paste text or Base64 to encode or decode instantly.

Upload a .txt file (max 5MB)

How This Base64 Tool Actually Encodes and Decodes Text

This tool runs on the browser's built-in btoa() and atob() functions rather than a custom encoder. Plain btoa() only accepts Latin-1 (single-byte) characters, so anything outside that range โ€” accented letters, emoji, CJK text, curly quotes โ€” throws InvalidCharacterError in a naive implementation. To avoid that, encoding here first runs your text through encodeURIComponent() and unescape() before handing it to btoa(), and decoding reverses the same chain with escape() and decodeURIComponent(). Practically, that means full UTF-8 text round-trips correctly โ€” something a bare btoa(text) call cannot do on its own.

What It Handles, and Where It Stops

  • โœ“ Text and .txt uploads only, up to 5MB: The file picker rejects anything without a .txt extension and anything over 5MB before it ever reaches the reader โ€” there's no server round-trip involved, the size check runs client-side against file.size.
  • โœ— No binary files (images, PDFs, zips): The uploader reads files as text via FileReader.readAsText(), which corrupts binary bytes. If you need to Base64-encode an image, use a dedicated image-to-Base64 converter that reads the file as a data URL instead.
  • โœ— Standard alphabet only, no Base64URL: Output uses + and / with = padding (RFC 4648 ยง4). If you're decoding a JWT segment or a URL query parameter that uses -/_ instead, swap those characters back to +// first or decoding will fail.
  • โœ“ Malformed input is caught, not silently mangled: Both operations run inside a try/catch โ€” an empty field throws immediately, and invalid Base64 (wrong padding, illegal characters) produces a visible error message rather than garbage output.

When You'd Actually Reach for This

Building a Basic Auth header by hand

HTTP Basic Authentication sends username:password Base64-encoded (not encrypted) in the Authorization header. Type alice:s3cret in, hit Encode, and prefix the result with Basic โ€” no curl or Postman needed for a quick check.

Reading a JWT payload

A JWT's middle segment is Base64URL-encoded JSON. Swap any -/_ to +//, pad with = to a multiple of 4, then decode here to inspect claims without pasting your token into a third-party JWT debugger.

Sanity-checking a data: URI

If a data: URI in your CSS or HTML isn't rendering, decode the Base64 payload after the comma to confirm it actually contains the bytes you think it does, rather than guessing.

Storing a small blob as text

Some config formats and text-only database columns can't hold arbitrary bytes. Encoding a short secret or token to Base64 first lets it travel safely through YAML, .env files, or CSV cells without escaping issues.

Frequently Asked Questions

I pasted Base64 and got "Error decoding Base64" โ€” why?

Usually one of three things: the string is missing its = padding, it contains whitespace/line breaks copied from a formatted source, or it's actually Base64URL (using -/_) rather than standard Base64. atob() is strict about the alphabet and throws on any of these.

Why does encoding a short emoji-only string produce such a long result?

Emoji are multi-byte in UTF-8 (often 4 bytes each), and the UTF-8-safe encoding path in this tool encodes those raw bytes, not the character count you see. A single emoji can turn into 6-8 Base64 characters.

Is Base64 the same as encryption?

No. Anyone can decode Base64 with no key at all โ€” it's a reversible text representation, not a cipher. Don't rely on it to hide passwords or secrets from anyone who can see the encoded string.

Can I upload an image file here?

The upload box only accepts .txt files and reads them as text, which would corrupt an image's binary data. Use this site's image-to-Base64 tool for images โ€” it reads files as data URLs instead of plain text.

Why is the encoded output roughly a third longer than my input?

Base64 packs 3 bytes of input into 4 output characters (using only 6 bits of information per character), which is a fixed 4:3 expansion โ€” about 33% larger before padding. That overhead is unavoidable with any standard Base64 encoder.