Base64 Encode & Decode

Turn text or files into Base64 and back again. Handles emoji, URL-safe output, data URIs and image previews.

100% Free Private & Secure Instant Conversion

How to Encode and Decode Base64

Three steps, no signup

1

Choose a mode

Pick Encode to turn text or a file into Base64, or Decode to turn Base64 back into text or a file.

2

Paste or drop your input

Type or paste into the input box, or use Encode a file and drop a file onto it. The result updates as you type.

3

Copy or download

Copy the output, download it as a text file, or download decoded binary data with the right file extension.

What Is Base64 Encoding?

Base64 is a way to write any binary data, such as an image, a PDF or a block of encrypted bytes, using only 64 printable characters: A-Z, a-z, 0-9, + and /. Because the output is plain text, it can travel through systems that only handle text, like email, JSON, XML, HTML and URLs. This tool encodes and decodes Base64 in your browser, for both text and files.

How Base64 Works

The encoder reads the input three bytes at a time. Three bytes are 24 bits, which it splits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and that number picks one character from the 64-character alphabet. So every 3 bytes become 4 characters, which makes Base64 output about 33% larger than the original.

When the input length is not a multiple of 3, the last group is short, and one or two = characters are added as padding. The text hello is 5 bytes and encodes to aGVsbG8=.

Common Uses of Base64

URL-Safe Base64

The standard alphabet uses + and /, which have special meaning in URLs and file paths, and = padding, which also needs escaping in a query string. URL-safe Base64 swaps + for - and / for _, and usually drops the padding. Tick the URL-safe box to encode this way. The decoder accepts either alphabet, with or without padding.

Base64 Is Encoding, Not Encryption

Base64 has no key and no secret. Anyone can reverse it in a second, as this page shows. Never use it to hide passwords, tokens or personal data. Its only job is to make binary data safe to store or send as text.

Standard vs URL-Safe Base64

FeatureStandardURL-safe
Last two characters+ and /- and _
Padding= to a multiple of 4Usually omitted
Defined inRFC 4648, section 4RFC 4648, section 5
Safe in URLs and filenamesNoYes
Typical useMIME email, data URIsJWTs, URL parameters

Base64 in JavaScript

The built-in btoa() and atob() only work on Latin-1 strings, so btoa() throws an error on emoji and most non-Latin text. Convert to UTF-8 bytes first:

const bytes = new TextEncoder().encode('héllo 👋');
const b64 = btoa(String.fromCharCode(...bytes));

const bin = atob(b64);
const text = new TextDecoder().decode(Uint8Array.from(bin, c => c.charCodeAt(0)));

In Node.js, use Buffer.from(text).toString('base64') and Buffer.from(b64, 'base64').toString(). This tool does the same UTF-8 step for you.

Base64 in Python

import base64

encoded = base64.b64encode('héllo'.encode('utf-8'))   # b'aMOpbGxv'
decoded = base64.b64decode(encoded).decode('utf-8')   # 'héllo'
safe = base64.urlsafe_b64encode(b'\xfb\xff')          # b'-_8='

Base64 on the Command Line

macOS and Linux both ship a base64 command. Use printf rather than echo so a trailing newline does not get encoded too:

printf 'hello' | base64          # aGVsbG8=
printf 'aGVsbG8=' | base64 -d    # hello
base64 photo.png > photo.txt     # encode a file
base64 -d photo.txt > photo.png  # decode it again

Linux wraps encoded output at 76 characters, so add -w 0 for a single line. macOS does not wrap by default.

Frequently Asked Questions

Common questions about Base64 encoding and decoding

Switch to Decode, paste your Base64 string and the text appears as you type. Line breaks, missing padding and the URL-safe alphabet are all accepted. If the data is not valid UTF-8 text, the tool shows its size and type and offers a file download instead.

Click Encode a file or drag the file onto the input box. The Base64 string appears right away. Tick Data URI to add a prefix such as data:image/png;base64, so you can paste the result straight into an img tag or a CSS url().

Base64 turns every 3 bytes into 4 characters. When the input length is not a multiple of 3, one or two = characters pad the last group. URL-safe Base64 usually leaves the padding out, and this decoder accepts it either way.

No. Base64 is a reversible encoding with no key, so anyone can decode it. It makes binary data safe to put in text formats, but it does not hide anything. Use real encryption to protect secrets.

Yes. Text is converted to UTF-8 bytes before encoding and decoded back the same way, so emoji, accented letters and scripts such as Chinese or Arabic round-trip correctly.

No. Encoding and decoding run entirely in your browser with JavaScript. Your text and files are never sent to a server.

More Free Image & Dev Tools

Convert images, data and code in your browser. All free, all private, no signup.

Browse All Tools