Base64 converter

Encode or decode Base64 for text, a file, or an image. Everything happens in this page — nothing you type or drop is ever uploaded, and this tool makes no network requests after it loads.

Text or file to encode empty
Options
Alphabet
Encode formatting
Output as
Base64 output empty

About this tool

Encode mode turns typed text or a dropped file into Base64. Decode mode does the reverse: paste a Base64 string — or a full data: URI — and get back text, an image preview, or a file to download, whichever fits what was actually inside it.

"Swap direction" takes whatever is currently in the output box, puts it back in as input, and flips the mode — useful for checking a round trip.

How it works

Byte-to-Base64 conversion uses the browser's built-in atob/btoa, the same approach as everywhere else on this site favouring a native API over a hand-written one where the browser already provides it correctly — MD5 on the hash generator page is hand-written only because Web Crypto omits it. Text is encoded and decoded as UTF-8. On decode, the page also looks at the first few bytes of the result — the same "magic number" check every operating system uses — to tell a PNG from a JPEG from plain text, so it can offer the right preview or file name without you having to know the format in advance.

Common questions

What is the URL-safe alphabet, and when do I need it?

Standard Base64 uses + and /, both of which mean something different inside a URL. The URL-safe variant replaces them with - and _ and drops the trailing = padding — the form used inside a JWT, for example. Decode auto-detects it when the input contains - or _ but no + or /; the checkbox is there to force it either way.

What's a data URI, and why would I want one?

A string of the form data:image/png;base64,iVBORw0… that a browser or CSS file can use directly in place of a linked file — handy for embedding a small icon without a separate request. Tick "Output as Data URI" and set the MIME type, which is filled in automatically from a dropped file where possible.

Is my file uploaded to encode or decode it?

No. Everything happens in your browser. There is no fetch, no beacon and no logging, and this page carries no third-party scripts.

How large a file can it handle?

Comfortably into the tens of megabytes; the guard rail refuses anything above 150 MB on encode (200 MB of Base64 text on decode) rather than freezing the tab. Larger files are a job for the command line — see below.

When encoding or decoding goes wrong

"Contains characters that are not valid Base64"

Base64 text uses only A–Z, a–z, 0–9, + and / (or - and _ for the URL-safe form), plus up to two trailing = padding characters. Anything else — including a stray line from an email client or a copy-paste artefact — has to be removed first. Whitespace and line breaks are stripped automatically, so those are never the cause.

"Length is not a multiple of four"

Base64 is always padded out to a multiple of four characters. A length that isn't almost always means the text was copied incompletely — check the start and end against the source.

Decoded output looks like garbage text

That's usually not text at all — an image or another binary format decoded and then forced through a text view will look like this. Check the image preview above the output, or just download it and open it with the right application.

A pasted data URI doesn't decode

Only the ;base64, form is supported. Some tools produce a URL-encoded data URI instead (percent signs rather than a Base64 block after the comma) — that's a different encoding entirely and needs decoding as a URL first.

Encoding a big file is slow, or the tab becomes unresponsive

Base64 inflates size by roughly a third, and it all has to sit in memory as a JavaScript string. The guard rail refuses anything past 150 MB before that becomes a problem — use the command line for anything bigger.

The same job at the command line

More tools

See the whole toolbox — twenty-six free tools planned, all running in your browser.