Skip to content
HandyKit

Base64 Encoder and Decoder

Convert text or files to Base64 and back. Unicode text, URL-safe Base64 and data URLs all work, and binary results can be previewed or downloaded.

Runs in your browser. Your input is never uploaded or stored.

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

  1. Choose Encode or Decode.
  2. To encode, type or paste text, or select Encode a file. The Base64 result appears as you type.
  3. To decode, paste Base64, URL-safe Base64 or a data: URL. Text appears straight away; binary data shows a preview and a download button.
  4. 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

Frequently asked questions

Is Base64 a form of encryption?

No. Base64 is an encoding, not encryption: anyone can decode it, with no key. It exists to carry binary data through systems built for text. Never use it to hide passwords or secrets.

Why is Base64 about a third larger than the original?

Base64 represents every 3 bytes with 4 characters, each carrying 6 bits. That is 4/3 the size, plus up to two "=" padding characters at the end.

What is URL-safe Base64?

A variant (often called Base64URL) that uses "-" and "_" instead of "+" and "/", which have special meanings in URLs and file names. It usually drops the "=" padding. JWTs use it. This tool decodes both variants automatically.

Why does my decoded result say "binary data"?

The decoded bytes are not valid UTF-8 text, so they are probably a file such as an image, PDF or archive. The tool shows the first bytes in hex, previews common image types, and lets you download the bytes as a file.

Is my data uploaded anywhere?

No. Encoding and decoding run in this browser tab, and files are read on your device. Nothing is sent to a server or stored.

What do the "=" signs at the end mean?

They are padding, which makes the length a multiple of four characters. One "=" means the last group held 2 bytes and two mean it held 1 byte. Many decoders, including this one, work without them.

Guides

  • · 5 min read

    What Is a JWT? Structure, Claims and Security

    A JSON Web Token is three Base64URL parts: header, payload and signature. Learn what each holds, how to read the claims, and why decoding is not verifying.