Base64 Encode & Decode

Encode text or a file to Base64, or decode Base64 back to text. Works with emoji and any language through UTF-8, and with URL-safe Base64.

Everything runs in your browser; nothing is uploaded.

Base64

This Base64 encoder and decoder converts text to Base64 and Base64 back to text, as you type. Unlike a quick btoa() in the console, it handles every language and emoji correctly by working with UTF-8 bytes. It also encodes whole files, decodes Base64 that turns out to be an image or PDF into a downloadable file, and tells you the exact character where a broken Base64 string goes wrong.

Examples

TextBase64Note
HelloSGVsbG8=5 bytes, one = of padding
HiSGk=2 bytes still make 4 characters
Hello, worldSGVsbG8sIHdvcmxk12 bytes divide by 3, so no padding
ุณู„ุงู…2LPZhNin2YU=4 Arabic-script letters are 8 UTF-8 bytes
๐Ÿ‘8J+RjQ==One emoji is 4 bytes
๐Ÿ‘ (URL-safe)8J-RjQ+ becomes -, padding dropped

How Base64 Works

Base64, defined in RFC 4648, takes the input three bytes (24 bits) at a time and splits them into four 6-bit groups. Each group, a number from 0 to 63, is written as one character from Aโ€“Z, aโ€“z, 0โ€“9, + and /. When the input is not a multiple of three bytes, the last group is padded with one or two = signs. Because those 64 characters survive almost any system that handles text, Base64 is how email attachments, images in CSS data URIs, keys in PEM files and the parts of a JSON Web Token are carried as plain text.

Options Explained

  • URL-safe (Base64URL): uses - and _ instead of + and /, without padding. Use it for tokens, URL parameters and file names.
  • Line breaks every 76 characters: the MIME format used in email (RFC 2045) and in PEM certificates, which wrap their Base64 at 64. Leave it off for JSON, HTML and code.
  • Encode a file: reads any file's bytes. For images you plan to put in HTML or CSS, the Image to Base64 converter adds the data URI and ready-made <img> and CSS snippets.
  • Swap: moves the result into the input and reverses direction, a quick way to check that a value survives the round trip.

When Decoding Fails

Characters outside the Base64 alphabet, such as *, % or a stray quote copied with the value, are pointed out with their position. Text after the = padding usually means two values were pasted together. A length error means a character was lost when copying. URL-encoded Base64 (%2B for +, %3D for =) needs to be URL-decoded first. Spaces and line breaks are ignored, so wrapped Base64 from an email or PEM file decodes as it is.

More Developer Tools

To read the claims inside a token, the JWT decoder decodes its Base64URL parts and checks the signature. Decoded JSON can be tidied in the JSON formatter.

Frequently Asked Questions

How do I decode Base64?

Choose Decode and paste the Base64 string. If it decodes to text, the text appears on the right. If it is a file, such as an image or a PDF, the tool says what kind of file it looks like and lets you download it.

Is Base64 encryption?

No. Base64 is an encoding: anyone can turn it back into the original with a tool like this one, with no key. It is used to carry binary data through places that only accept text, such as JSON, email or URLs, not to hide it.

Why is the Base64 longer than my text?

Every 3 bytes become 4 Base64 characters, so the output is about a third larger than the input, plus up to two = signs of padding. Characters outside basic English take 2 to 4 bytes each in UTF-8, so text in Urdu, Arabic or Chinese, or with emoji, grows more.

What is URL-safe Base64?

Base64URL replaces + with - and / with _, and usually drops the = padding, so the result can go in a URL or file name unchanged. JSON Web Tokens use it. The decoder accepts both kinds, and also strips a data: URI prefix if you paste one.

Why does my decoded text look garbled?

The original was probably not UTF-8: for example, text saved in an old Windows code page. It can also mean the Base64 is a binary file rather than text. This decoder reads text as UTF-8, which is what almost all modern systems use.

Why does btoa() fail with my text?

JavaScript's btoa() only accepts characters with codes up to 255, so it throws an InvalidCharacterError on emoji and most non-Latin text. Convert the text to UTF-8 bytes first, with TextEncoder, and encode those, which is what this tool does.

Is there a size limit?

Text has no set limit. Files up to 25 MB can be encoded; past that the Base64 text becomes too long to use comfortably in a browser text box.