Home › Base64 Encoder & Decoder

Base64 Encoder & Decoder

Output

File → Base64

Pick an image, font or any file. It is read locally with the FileReader API and never uploaded.

Data URI
Raw Base64

How Base64 works

Base64 takes the input bytes, splits them into groups of 24 bits (3 bytes) and maps each 6-bit chunk to one of 64 printable characters: A–Z, a–z, 0–9, + and /. If the input length is not a multiple of 3, the output is padded with one or two = characters. For example, Man (bytes 77 97 110) becomes TWFu, and Ma becomes TWE=.

Because Base64 works on bytes, text must first be turned into bytes using a character encoding. This tool always uses UTF-8, the encoding used by the web, JSON and virtually all modern APIs. That is why héllo encodes to aMOpbGxv — the é is two bytes (C3 A9) in UTF-8.

Where you meet Base64

Encoding Base64 in code (UTF-8 safe)

// Browser / modern JS
const b64 = btoa(String.fromCharCode(...new TextEncoder().encode(text)));
const txt = new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0)));

// Node.js
Buffer.from(text, 'utf8').toString('base64');      // 'base64url' for URL-safe

# Python
base64.b64encode(text.encode('utf-8')).decode()

# Shell
echo -n 'héllo' | base64      # -n matters: without it the newline is encoded too

Decoding tips

Frequently asked questions

Why does btoa() throw 'The string to be encoded contains characters outside of the Latin1 range'?

btoa() only accepts characters with code points 0-255. To encode text such as 'héllo' or emoji you must first convert it to UTF-8 bytes, e.g. with new TextEncoder().encode(text), and then Base64-encode those bytes. This tool does exactly that.

Is Base64 encryption?

No. Base64 is an encoding, not encryption. Anyone can decode it without a key. Never use Base64 to hide passwords or secrets; it only makes binary data safe to transport as text.

What is URL-safe Base64?

URL-safe Base64 (RFC 4648 section 5, often called base64url) replaces + with - and / with _ and usually drops the trailing = padding, so the value can be placed in URLs and filenames without escaping. JWTs use base64url.

Why is Base64 output bigger than the input?

Base64 represents every 3 bytes as 4 characters, so the output is about 33% larger than the input (plus up to 2 padding characters).