What is Base64?
Base64 is a way to write any data, including images, files and binary keys, using only 64 safe text characters: A–Z, a–z, 0–9, + and /, with = as padding. It is defined in RFC 4648. It is used wherever binary data has to pass through a system designed for text: email attachments, data URLs in HTML and CSS, JSON APIs that carry files, Basic authentication headers and JWTs.
For example, the text Hi! is three bytes, 48 69 21 in hex. Base64 splits those 24 bits into four groups of 6 bits and maps each to a character:
Hi! → SGkh
How to encode or decode Base64
- Choose Encode or Decode.
- To encode, type or paste text, or select Encode a file. The Base64 result appears as you type.
- To decode, paste Base64, URL-safe Base64 or a
data:URL. Text appears straight away; binary data shows a preview and a download button. - Select Copy or Download to use the result.
Text, Unicode and the btoa problem
Base64 encodes bytes, not characters, so text must first be turned into bytes. This tool uses UTF-8, the encoding used by the web, so every language and emoji works.
That is also why JavaScript’s built-in btoa() fails on most text: it only accepts characters in the Latin-1 range, so btoa("café ☕") throws an error. Encode to UTF-8 first:
// Modern browsers
const base64 = new TextEncoder().encode('café ☕').toBase64();
const text = new TextDecoder().decode(Uint8Array.fromBase64(base64));
// Node.js
Buffer.from('café ☕').toString('base64');
Buffer.from(base64, 'base64').toString('utf8');
URL-safe Base64
Standard Base64 uses + and /, which mean something in URLs and file paths. URL-safe Base64 (Base64URL) replaces them with - and _ and usually leaves out the = padding. You will see it in JWTs, URL parameters and file names. When decoding, this tool detects which variant you pasted, so you don’t need to choose.
Data URLs
A data URL embeds a file directly in a link or stylesheet:
data:image/png;base64,iVBORw0KGgo…
Select Encode a file and tick Output as a data URL to create one. Paste a data URL into Decode to preview the image or download the file. Data URLs suit small images and icons; for anything large, a normal file is faster, because Base64 adds a third to the size and the browser cannot cache it separately.
Base64 is not encryption
Anything Base64-encoded can be decoded by anyone, instantly. The Authorization: Basic header, for example, is just username:password in Base64, which is why it must only be sent over HTTPS. If data must stay secret, encrypt it.
On the command line
echo -n 'Hi!' | base64 # SGkh
echo 'SGkh' | base64 -d # Hi! (use -D on older macOS)
base64 -i photo.png -o photo.b64