Home › Base64 Encoder & Decoder
Base64 Encoder & Decoder
File → Base64
Pick an image, font or any file. It is read locally with the FileReader API and never uploaded.
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
- HTTP Basic auth: the header
Authorization: Basic dXNlcjpwYXNzis justuser:passin Base64 — which is why Basic auth must only be used over HTTPS. - Data URIs:
data:image/png;base64,iVBORw0…embeds small images directly in HTML or CSS. - JWTs and many API tokens use base64url for their segments.
- Email attachments (MIME) and Kubernetes
Secretvalues are Base64-encoded.
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
- Whitespace and line breaks (common in PEM files and emails) are ignored by the decoder.
- Both standard and URL-safe alphabets are accepted, and missing
=padding is added automatically. - If the decoded bytes are not valid UTF-8 (for example a binary file), the tool shows a hex dump instead of garbled text.
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).