Base64 Encode and Decode (Text and Files)

Encode text or files to Base64 and decode Base64 back to text, with UTF-8 and URL-safe Base64url support. Runs entirely in your browser.

Runs in your browser. Nothing is uploaded.

Example

Input:

Héllo, Pakistan 👋

Result:

SMOpbGxvLCBQYWtpc3RhbiDwn5GL

What Base64 is for

Base64 turns any bytes into 64 safe ASCII characters so binary data can travel through systems built for text: data: URLs, JSON payloads, email attachments, HTTP Basic auth headers and JWT segments. It is an encoding, not encryption: anyone can decode it, so never use it to hide secrets.

Encoded output is about 33% larger than the input, because every 3 bytes become 4 characters. That is why embedding large images as data URLs makes pages heavier; it only pays off for very small icons.

UTF-8 and the btoa trap

The browser's built-in btoa() only accepts characters up to code point 255, so btoa("é") works but btoa("👋") throws. This tool first encodes text as UTF-8 bytes with TextEncoder and then Base64-encodes the bytes, and decodes the reverse way with TextDecoder, so accents, Urdu, Arabic and emoji round-trip correctly. In Node.js the equivalent is Buffer.from(text, "utf8").toString("base64").

Decoding has the opposite trap: atob() returns a "binary string" with one character per byte, so atob() on Base64 of "é" gives two odd characters instead of one letter. Converting those bytes with TextDecoder fixes it, and the decoder here reports clearly when the bytes are not text at all, for example when the Base64 is really an image or a PDF. Newer browsers also offer Uint8Array.fromBase64() and toBase64(), which do the byte conversion for you.

Base64url and files

Base64url replaces + and / with - and _ and usually drops the = padding, so the result is safe in URLs and file names. JWTs use it, which is why a JWT cannot be decoded with a plain atob() call without converting it first. Switch the URL-safe option on to produce or read that variant.

You can also pick a file to get its Base64 or a ready-made data: URL, for example to inline a small SVG in CSS or to send a file inside a JSON API request during testing. The file is read locally with the FileReader API and never uploaded.

Frequently asked questions

Is Base64 encryption?

No. It is a reversible encoding anyone can decode. Use real encryption for secrets.

Why does btoa fail with emoji?

btoa only accepts Latin-1 characters. Encode the text to UTF-8 bytes first, as this tool does.

What is Base64url?

A URL-safe variant that uses - and _ instead of + and / and often omits padding. JWTs use it.

Are my files uploaded?

No. Files are read in your browser with the FileReader API.

Related tools