Base64 encoding turns arbitrary bytes into a text string built from 64 printable ASCII characters. Developers use it when binary data must travel through JSON, XML, email (MIME), or URL-adjacent contexts that expect text, not raw bytes. It is encoding, not encryption: anyone can decode it. This guide explains how Base64 works under RFC 4648, how it differs from Base64URL and hex, and how to encode and decode Base64 online with our free Base64 Encoder and related tools. Processing runs in your browser; your payloads are not uploaded for server-side conversion.
Printable Symbols
Standard Alphabet
Typical Size Overhead
Bytes to Chars
Key facts: Base64 encoding (quick reference)
Use this block when you need a concise answer for search or AI summaries:
- Alphabet:
A–Z,a–z,0–9,+,/. Padding uses=(not a data symbol). - Block size: Every 3 input bytes (24 bits) become 4 output characters (4×6 bits).
- Example:
Hello, World!encodes toSGVsbG8sIFdvcmxkIQ==. - Not secret: Base64 obfuscates nothing. Use TLS, encryption, and proper secrets management for sensitive data.
- Base64URL: JWT and many URLs replace
+//with-/_and often omit padding (RFC 4648 section 5). - Data URLs:
data:image/png;base64,iVBORw0KGgo=...embeds small assets in HTML or CSS. - Privacy: Our Base64 Encoder encodes locally in JavaScript via
btoaandFileReader.
What is Base64 encoding?
Base64 is a binary-to-text encoding defined in RFC 4648. It maps each sequence of three octets to four characters from a fixed 64-character alphabet so the result survives transports that were designed for 7-bit or UTF-8 text (SMTP, JSON fields, query strings with care, and log pipelines).
Common reasons developers search for what is Base64 encoding or base64 explained:
- REST APIs: Attach a PDF, image, or protobuf blob as a Base64 string inside JSON.
- Email (MIME): Encode attachments when messages must stay 7-bit safe on legacy relays.
- Web assets: Inline tiny icons with
data:URLs to cut HTTP requests. - Tokens: JWT header and payload segments look like Base64, but they use the URL-safe variant without padding in many libraries.
- Config and logs: Copy encoded certificates, Basic auth headers, or binary snippets from DevTools.
- Debugging: Tell whether a string is text, hex, or Base64 before passing it to the next tool.
Figure 1: How 3 bytes become 4 Base64 characters (RFC 4648).
How Base64 encoding works (step by step)
- Read input bytes left to right (a file, UTF-8 text, or any binary stream).
- Form 24-bit groups by concatenating three 8-bit bytes. If the final group is short, pad with zero bits as described in RFC 4648.
- Split each 24-bit group into four 6-bit numbers (values 0–63).
- Index the alphabet to pick characters
A–Z(0–25),a–z(26–51),0–9(52–61),+(62),/(63). - Add padding
=so the encoded length is a multiple of four characters when the spec requires it.
Padding rules for the last quantum:
- 1 byte left: 2 characters plus
==(example:M→TQ==). - 2 bytes left: 3 characters plus
=(example:Ma→TWE=). - 3 bytes: 4 characters, no padding (example:
Man→TWFu).
Base64 vs Base64URL vs hex
| Format | Character set | Padding | Typical use |
|---|---|---|---|
| Base64 (RFC 4648 §4) | + and / |
= when needed |
MIME, generic APIs, data: URLs |
| Base64URL (RFC 4648 §5) | - and _ |
Often omitted in JWT | JWT segments, URL path/query tokens |
| Hex (Base16) | 0–9A–F |
None | Hashes, certificates, debug dumps |
If you are working with JWTs, read our JWT token decoding guide and use the JWT Decoder & Verifier. JWT payloads are signed or encrypted JSON, not "hidden" because they are Base64URL-wrapped.
Method 1: Encode or decode Base64 online (OnlineMiniTools)
Encode text or a file
- Open the Base64 Encoder.
- Choose the Text tab, paste or type your string, and wait for live output in Encoded Output (about 200 ms debounce).
- For binary files, switch to the File tab, upload any file up to 50 MB, and click Encode File.
- Copy the result or download
encoded-base64.txtfrom the output panel.
The encoder uses the browser btoa API for text and FileReader.readAsDataURL for files (stripping the data:*;base64, prefix). Encoding stays on your device.
Decode Base64 back to text
- Open the Base64 Decode tool.
- Paste the Base64 string (with or without a
data:prefix, depending on the tool UI). - Read the decoded text output and copy it for your app or script.
For images, try the Base64 to Image Converter to preview PNG or JPEG bytes. To validate padding and alphabet before decoding, use the Base64 Validator.
Alternative methods (CLI and code)
Linux and macOS terminal
# Encode (note: -n avoids trailing newline on GNU coreutils)
echo -n 'Hello, World!' | base64
# Decode
echo 'SGVsbG8sIFdvcmxkIQ==' | base64 -d
On macOS, base64 may add a newline by default; use echo -n or pipe from a file for exact bytes.
Python 3
import base64
text = "Hello, World!"
encoded = base64.b64encode(text.encode("utf-8")).decode("ascii")
decoded = base64.b64decode(encoded).decode("utf-8")
print(encoded, decoded)
Node.js
const text = "Hello, World!";
const encoded = Buffer.from(text, "utf8").toString("base64");
const decoded = Buffer.from(encoded, "base64").toString("utf8");
console.log(encoded, decoded);
Browser console (Latin-1 caveat)
btoa("Hello, World!"); // SGVsbG8sIFdvcmxkIQ==
atob("SGVsbG8sIFdvcmxkIQ=="); // Hello, World!
UTF-8 text: btoa throws on code points above U+00FF. Encode UTF-8 bytes first (for example TextEncoder plus a byte-to-string helper) or use a library. Our encoder follows the same btoa behavior for plain text input.
OpenSSL
echo -n 'Hello, World!' | openssl base64
echo 'SGVsbG8sIFdvcmxkIQ==' | openssl base64 -d
Tips and common mistakes
- Encoding vs encryption: Never store passwords or API keys "protected" by Base64 alone.
- Whitespace: PEM certificates and some logs wrap Base64 with newlines every 64 characters. Strip whitespace before decoding if your tool requires a single line.
- URL-safe variants: Replace
-→+and_→/, restore padding, then decode standard Base64. - Wrong alphabet: Hex strings (only
0-9A-F) are not Base64. Use a hex decoder instead. - Size overhead: Output grows by roughly 33% plus padding. Large files belong in object storage with signed URLs, not giant JSON fields.
- Gzip inside Base64: API payloads may be gzip-compressed then Base64-wrapped. Decode Base64 first, then use Gzip Decompress if bytes start with
1F 8B. - Canonical padding bits: RFC 4648 requires encoders to zero pad bits in the last quantum. Some strict decoders reject non-zero pad bits.
Related free tools
For a single page that maps every encode/decode workflow (text, images, SVG, MP3, files), see Base64 Tools Hub: Encode, Decode, SVG, MP3, and Images.
- Base64 Encoder - Live text encoding and file upload up to 50 MB.
- Base64 Decode - Turn encoded strings back into readable text in the browser.
- Image to Base64 - Encode PNG, JPEG, and other images for CSS or HTML.
- Base64 Validator - Check padding and character set before you ship data to production.
Frequently Asked Questions
What is Base64 encoding used for?
Base64 encoding represents binary data as ASCII text so it can move through JSON, XML, email, and similar text-only channels without byte corruption. It is also used in data URLs, some API attachment fields, and transport wrappers around compressed data.
Is Base64 the same as encryption?
No. Base64 is a reversible encoding with a public alphabet. Anyone can decode it. Use HTTPS, encryption, and proper secret storage when data must stay confidential.
Why does my Base64 string end with equals signs?
Padding characters (=) make the encoded length a multiple of four. They mark how many bytes were in the final partial block. Some URL-safe formats omit padding, but standard RFC 4648 Base64 includes it unless another spec says otherwise.
What is the difference between Base64 and Base64URL?
Base64URL replaces + and / with - and _ so encoded strings are safer in URLs and filenames. JWT libraries typically use Base64URL without padding. Convert to standard Base64 before decoding with strict RFC 4648 tools if needed.
How do I encode text to Base64 online for free?
Paste your text into our Base64 Encoder, choose the Text tab, and copy the Encoded Output. Encoding runs locally in your browser with no account required.
Whether you are wrapping a file for an API, inlining a tiny asset, or debugging a log line, understanding Base64 encoding saves time and prevents false "encryption" assumptions. Open the free Base64 Encoder to convert text or files, pair it with Base64 Decode when you need the original bytes back, and keep this guide handy for padding, URL-safe variants, and UTF-8 edge cases.