Skip to content

Base64 encode and decode

Encode and decode Base64 text and files.

Mode

Your text stays in this browser

First 3 bytes
Wrap at

Base64 is an encoding, not encryption. Anyone can decode it, so never treat it as a way to hide a password.

What Base64 is and is not

To Base64 encode and decode is to move data between raw bytes and plain text made of 64 safe characters: the letters A to Z and a to z, the digits 0 to 9, and two symbols. It exists because systems such as email, JSON and URLs were built for text and mangle raw bytes.

It is an encoding, not encryption: there is no key, and anyone who sees the string can turn it back. The text cGFzc3dvcmQ= is simply the word "password" written in a different alphabet.

How 3 bytes become 4 characters

Three bytes are 24 bits. Base64 cuts those 24 bits into four groups of 6 bits, and each group, a number from 0 to 63, picks one character from the alphabet. The word "Man" becomes TWFu: the bits 010011 010110 000101 101110 are the numbers 19, 22, 5 and 46, which are T, W, F and u.

Input 3 bytes 4 characters, no padding 2 bytes = 3 characters + 1 "=" 1 byte 2 characters + 2 "="
Solid boxes are bytes in (top) and characters out (below). Dashed boxes are missing; the output is topped up with "=".

So the output is always about a third longer than the input.

What the = signs mean

The 4-for-3 pattern only fits when the input length is a multiple of three. When it is not, the last group is short, and the encoder adds one or two = characters so the length stays a multiple of four. Some formats drop them (use the No padding button), but standard Base64 keeps them.

Padding by input length
Bytes left overCharacters outPaddingExample
0 (multiple of 3) 4 none "Man" becomes TWFu
2 3 = "Ma" becomes TWE=
1 2 == "M" becomes TQ==

Source: RFC 4648, section 4 and section 3.2.

Which Base64 variant is this?

Standard Base64 uses + and /, and both mean something in a URL or a file path. The URL-safe form swaps them for - and _. This tool's decoder accepts either form, with or without padding, so a JWT segment decodes without edits.

Four common dialects
VariantSymbolsPaddingLine breaksFound in
Standard + / Yes None JSON fields, data URIs
URL-safe - _ Often dropped None JWTs, links, file names
MIME + / Yes Every 76 characters Email attachments
PEM + / Yes Every 64 characters Certificates and keys

Source: RFC 4648 sections 4 and 5; RFC 2045 section 6.8; RFC 7468.

The decoder ignores line breaks and spaces, so wrapped text decodes the same as unwrapped.

Why accented letters and emoji break

Base64 encodes bytes, not letters, so text has to become bytes first. This tool uses UTF-8, which is what the web, JSON and most modern systems use. The letter "e" is one byte; "é" is two; an emoji is four. The encoding of "é" is w6k=, not the 6Q== you get if a tool treats text as Latin-1.

Garbled output after decoding usually means the two sides disagree on this step. JavaScript's built-in btoa() only accepts characters up to code 255, so code that calls it directly fails on emoji or on Chinese, Arabic or Hindi text; the safe route is TextEncoder first, which is what this page does.

Data URIs and the size cost

A data URI puts a whole file inside a link: data:image/png;base64,iVBORw0…. The part before the comma names the type; the part after is the file. The cost is the extra third, and the file can no longer be cached on its own.

What Base64 does to file size
OriginalAs Base64Extra
1 KB (1,024 bytes) 1,368 bytes +33.6%
100 KB (102,400 bytes) 136,536 bytes +33.3%
1 MB (1,048,576 bytes) 1,398,104 bytes +33.3%

Source: calculated as 4 × ceil(bytes ÷ 3), padded, no line breaks.

As a rule, inline only small images such as icons. To make a photo smaller before encoding, use the image compressor.

Going the other way

Paste a data URI or Base64 file into the Base64 box: the tool recognizes the type from its first bytes, previews images and offers a download.

Where you will meet Base64

Common places and what is inside
PlaceWhat is encodedVariant
JSON Web Tokens Header and payload as JSON; readable by anyone URL-safe, no padding
HTTP Basic authentication The text user:password Standard
Email attachments The attached file MIME
Data URIs in HTML and CSS A small image or font Standard
PEM certificates and keys DER binary data between BEGIN and END lines PEM

Source: RFC 7519; RFC 7617; RFC 2045; RFC 2397; RFC 7468.

The first two rows show why "it is encoded" never means "it is safe". The payload of a JWT is only signed, not hidden (its JSON can be tidied in our JSON formatter once decoded, and its exp time read with the Unix timestamp converter), and a Basic authentication header sends the password in a form anyone on the path can read unless HTTPS protects it. On this page the text you type or convert, and any file, stays in your browser and is not sent by the page, although the site does count page views. For raw bytes rather than text, the binary and hex converter shows the same data as hex.

Common questions

Why do I get "not a Base64 character" for text that looks right?

Usually a stray character: a quotation mark, a trailing comma copied from JSON, a "Bearer" word, or a symbol that the URL changed. The error names the character and its position. Spaces and line breaks are not a problem.

Sources

Last reviewed November 9, 2026.