Base64 Encoder & Decoder
Paste text above to convert it to Base64, or switch to Decode to turn Base64 back into readable text. You can also drop a file onto the input to get its Base64 representation. Everything runs in your browser, so your data never leaves your device.
What is Base64?
Base64 is a binary-to-text encoding scheme. It represents arbitrary binary data — images, files, encrypted bytes, anything — using only 64 printable ASCII characters that survive transmission through systems designed for text. It is defined in RFC 4648.
The name comes from the size of its alphabet: 64 symbols, which is exactly 26. That matters because 6 bits can express 64 distinct values, so Base64 maps every 6 bits of input to one output character.
Why Base64 exists
Many older protocols and formats were built to carry text, not raw bytes. Email (SMTP), for example, was historically a 7-bit channel: send raw binary through it and bytes could be stripped, reordered, or mangled. The same risk applies when you embed binary inside JSON, XML, a URL, an HTML attribute, or a cookie. Base64 sidesteps this by re-expressing binary using a small, universally safe character set, so the data passes through untouched and can be decoded back to the exact original bytes on the other side.
The Base64 alphabet
Standard Base64 uses these 64 characters, indexed 0–63:
- Index
0–25→A B C … Z(uppercase letters) - Index
26–51→a b c … z(lowercase letters) - Index
52–61→0 1 2 … 9(digits) - Index
62→+· Index63→/
A 65th character, =, is used only for padding (explained below). It is not part of the 64-symbol alphabet.
How Base64 encoding works, step by step
The core idea: take input 3 bytes at a time (24 bits), then re-slice those 24 bits into four 6-bit groups, and map each group to a character. Three bytes in → four characters out.
Worked example: encoding "Man"
- Take the ASCII codes:
M = 77,a = 97,n = 110. - Write them in 8-bit binary:
01001101 01100001 01101110. - Join into one 24-bit string and re-group into 6-bit chunks:
010011 010110 000101 101110. - Convert each chunk to decimal:
19, 22, 5, 46. - Look up the alphabet:
19→T,22→W,5→F,46→u.
Result: Man encodes to TWFu. Try pasting Man into the encoder above to confirm.
Padding and the = sign
Input isn't always a neat multiple of 3 bytes. Base64 handles the leftovers by padding the final group with = so output length is always a multiple of 4.
- 3 bytes → 4 chars, no padding. Example:
abc→YWJj. - 2 bytes → 4 chars with one
=. Example:ab→YWI=. - 1 byte → 4 chars with two
==. Example:a→YQ==.
So a trailing = or == simply tells the decoder how many bytes the final group really represented.
How decoding works
Decoding reverses the process: each character maps back to its 6-bit value, the bits are concatenated, then re-sliced into 8-bit bytes, dropping any extra bits introduced by padding. Decoding TWFu walks the steps above in reverse and returns Man.
Size overhead: why Base64 is bigger
Because every 3 bytes become 4 characters, Base64 output is roughly 33% larger than the input (4÷3 ≈ 1.33). Padding and any line breaks add a little more. A 9 KB image becomes about 12 KB encoded. This is the trade-off for safe text transport, and it's why you embed small assets as Base64 but rarely large ones.
Base64 variants
Standard Base64
Uses + and / and keeps = padding. This is the default and what most APIs expect.
URL- and filename-safe Base64
The characters + and / are unsafe in URLs and file paths (/ is a path separator; + can mean a space). The URL-safe variant replaces them with - and _ and usually omits padding. Example: standard a+b/c== becomes URL-safe a-b_c. Enable the URL-safe toggle above to produce this form. It is widely used in JWTs (JSON Web Tokens), OAuth tokens, and signed URLs.
MIME Base64
Used in email, this variant wraps output into lines of 76 characters separated by CRLF, per the MIME spec. The alphabet is the standard one; only line wrapping differs.
Data URIs: Base64 in the browser
A common use is embedding a file directly inside HTML or CSS as a data: URI, avoiding a separate network request:
<img src="data:image/png;base64,iVBORw0KGgo...">background:url("data:image/svg+xml;base64,PHN2Zy...")
The pattern is data:[media-type];base64,[the-base64-data]. Best for tiny icons and inline SVGs; large images bloat your HTML/CSS and hurt caching.
Common use cases
- Email attachments — MIME encodes attached files in Base64.
- Embedding images/fonts — data URIs in HTML, CSS, and SVG.
- JSON & APIs — sending binary fields (e.g. file uploads) as Base64 strings.
- JWT & tokens — the header and payload of a JSON Web Token are URL-safe Base64.
- Basic Auth — HTTP sends
username:passwordas Base64 in theAuthorizationheader (which is exactly why Basic Auth needs HTTPS). - Storing binary in text-only stores — config files, cookies, localStorage, environment variables.
Base64 in code
Most languages include Base64 in their standard library. A few quick references:
JavaScript
- Encode (ASCII):
btoa("Man")→"TWFu" - Decode:
atob("TWFu")→"Man" - For full Unicode, encode bytes first:
btoa(String.fromCharCode(...new TextEncoder().encode(str)))
Python
import base64- Encode:
base64.b64encode(b"Man")→b'TWFu' - Decode:
base64.b64decode("TWFu")→b'Man' - URL-safe:
base64.urlsafe_b64encode(...)
Java
- Encode:
Base64.getEncoder().encodeToString("Man".getBytes()) - Decode:
new String(Base64.getDecoder().decode("TWFu")) - URL-safe:
Base64.getUrlEncoder()/getUrlDecoder()
Command line
- Encode:
echo -n "Man" | base64→TWFu - Decode:
echo "TWFu" | base64 --decode→Man
Base64 vs related concepts
Base64 vs encryption: Base64 provides zero confidentiality. It is reversible by anyone, instantly. Encryption requires a key and is designed to hide data; Base64 only reformats it.
Base64 vs hashing: A hash (like SHA-256) is one-way and fixed-length; you cannot recover the input. Base64 is two-way and length-proportional. They're often combined — a hash's raw bytes are frequently shown in Base64 for readability.
Base64 vs URL encoding: URL/percent-encoding (%20 for a space) escapes individual unsafe characters in text. Base64 transforms the entire byte stream. They solve different problems and are sometimes layered.
Frequently asked questions
Is Base64 the same as encryption?
No. Base64 is encoding, not encryption. It hides nothing — anyone can decode it in seconds. Never use Base64 to protect passwords or sensitive data; use real encryption for that.
Why does encoded output end with one or two = signs?
Base64 processes data in groups of three bytes that map to four characters. When the input length isn't a multiple of three, = padding is added to fill out the final group: one = for a 2-byte remainder, two == for a 1-byte remainder.
What is the difference between Base64 and Base64URL?
Base64URL is the URL- and filename-safe variant. It swaps + → - and / → _ and usually drops = padding, so the result is safe inside URLs, query strings, and filenames. It's the encoding used in JWTs.
How much larger does Base64 make my data?
About 33% larger, because 3 input bytes become 4 output characters (a 4:3 ratio). Padding and optional line breaks add a little extra.
Can I encode images, PDFs, or other files?
Yes. Use the Upload file button or drag a file onto the input panel. The tool returns the file's Base64, commonly used in data URIs and embedded assets.
Why does my decoded text look like garbled characters?
Usually a character-set mismatch. If the original was UTF-8 (accents, emoji, non-Latin scripts), decode with UTF-8 selected. Decoding UTF-8 data as ASCII produces mojibake. Also check you haven't mixed standard and URL-safe forms.
Is my data sent to a server?
No. All conversion happens locally with JavaScript in your browser. Nothing you type or upload is transmitted or stored anywhere.