MSMuhammad Shahid

Free tool · runs in your browser

Base64 encoder and decoder

Encode text to Base64 or decode Base64 back to text, including emoji and non-English characters, with an optional URL-safe format.

Quick answer

Base64 turns any data into text made of 64 safe characters, so it can travel through systems that only handle text, such as JSON, URLs or email. It is an encoding, not encryption: anyone can decode it. URL-safe Base64 (Base64URL) replaces + and / with - and _ and drops the padding, which is what JWTs use.

How to use it

  1. Choose encode or decode. Encode turns text into Base64; decode turns Base64 back into text.
  2. Paste your input. Text in any language works, because it is converted as UTF-8.
  3. Pick URL-safe if needed. Use it for URLs, file names and JWTs.

Example

Text with an emoji, encoded as UTF-8 Base64:

Input

Hello, world! 👋

Output

SGVsbG8sIHdvcmxkISDwn5GL

Common errors and how to fix them

InvalidCharacterError: The string contains characters outside of the Latin1 range
btoa() only accepts Latin-1 text. Convert the text to UTF-8 bytes first with TextEncoder, as this tool does, or use Buffer.from(text).toString('base64') in Node.js.
The string to be decoded is not correctly encoded
The input has characters that are not Base64, such as spaces or line breaks from copying, or it is URL-safe Base64 with - and _. Remove the extra characters or use the URL-safe option.
Decoded text looks like café
UTF-8 bytes were read as Latin-1. Decode the bytes as UTF-8, for example with TextDecoder.
+ turns into a space in a URL
Standard Base64 uses +, which URLs read as a space. Use URL-safe Base64, or encode the value with encodeURIComponent.

Frequently asked questions

Is Base64 encryption?

No. Base64 only changes how data is written; anyone can decode it. Use real encryption for secrets.

Why does Base64 make data bigger?

Every 3 bytes become 4 characters, so encoded data is about 33% larger.

What is URL-safe Base64?

A variant that uses - and _ instead of + and /, and usually drops the = padding, so it can be used in URLs and file names.

Why does decoding give strange characters?

The input may not be text (for example an image), may not be valid Base64, or may use the URL-safe alphabet; try the URL-safe option.

Is my data uploaded?

No. Encoding and decoding run in your browser.

How do I encode Base64 in JavaScript?

btoa() works for ASCII text; for any UTF-8 text, convert it to bytes first with TextEncoder, as this tool does. In Node.js, use Buffer.from(text).toString("base64").

What is a data URL?

A way to embed a file directly in a page as Base64, such as data:image/png;base64, followed by the encoded data.

What is the = at the end of Base64?

Padding that makes the length a multiple of 4. URL-safe Base64 usually leaves it out.

Can I encode images or files here?

This tool encodes text. Files can be Base64-encoded too, but they become about a third larger.

Is standard Base64 safe to use in URLs?

No. It contains + and /, which have special meanings in URLs; use the URL-safe variant instead.

Sources

Related

More tools in this group

Guides and apps