What is Base64?
Learn how Base64 turns bytes into transport-friendly text, why it adds size, where padding comes from, how Base64URL differs, and why encoding is not encryption.
Base64 represents bytes using readable ASCII characters
It was designed for moving binary data through systems that reliably handle text. It changes representation, not the underlying meaning or security of the data.
Any sequence of bytes
Text, images, PDFs, cryptographic values, and arbitrary files can all be encoded.
A restricted text alphabet
Standard Base64 uses A-Z, a-z, 0-9, plus, slash, and optional equals-sign padding.
Readable, not protected
No key is required to decode it. Use encryption and access controls when confidentiality matters.
How Base64 encoding works
The encoder reads three bytes at a time, splits their 24 bits into four groups of six bits, and maps each group to one Base64 character.
01001000 01101001 0010000124 input bits010010 000110 100100 100001Four 6-bit valuesSGkhMapped through the Base64 alphabetMan → TWFuNo padding is needed.
Ma → TWE=One padding character may appear.
M → TQ==Two padding characters may appear.
Three bytes become four ASCII characters, producing roughly 33% overhead. For an input of n bytes, the padded output length is approximately 4 × ceil(n / 3).
Base64 vs Base64URL
URLs and filenames give special meaning to some standard Base64 characters, so web tokens commonly use a URL-safe alphabet.
| Feature | Standard Base64 | Base64URL |
|---|---|---|
| Characters 62 and 63 | + and / | - and _ |
| Padding | = commonly retained | = commonly omitted |
| Typical use | Email, files, data payloads | JWT, URL parameters, web-safe identifiers |
Where developers use Base64
JSON and API payloads
Small binary values may be carried in JSON, but multipart or binary upload is better for large files.
Data URLs
Small images can be embedded as data:image/png;base64,..., avoiding a separate request.
Web tokens
JWT segments use Base64URL to remain compact and URL-safe.
Email attachments
MIME uses transfer encodings so binary attachments can pass through text-oriented email systems.
HTTP Basic authentication
The username and password are Base64 encoded, not encrypted, so HTTPS is mandatory.
Configuration transport
Some tools carry certificates or bytes as text, but secret-management protections are still required.
Good fit
- Small binary values in text-only formats
- Compact data URLs for tiny assets
- Protocol-required transfer encoding
Avoid when
- The protocol already supports binary uploads
- The file is large or memory is limited
- You need confidentiality rather than compatibility
Encode and decode UTF-8 text correctly
Base64 operates on bytes. Always use an explicit character encoding such as UTF-8 for international text.
Browser JavaScript
const bytes = new TextEncoder().encode('Hello');
const binary = String.fromCharCode(...bytes);
const encoded = btoa(binary);
const decodedBytes = Uint8Array.from(
atob(encoded), char => char.charCodeAt(0)
);
const text = new TextDecoder().decode(decodedBytes);C# / .NET
var bytes = Encoding.UTF8.GetBytes("Hello");
var encoded = Convert.ToBase64String(bytes);
var decodedBytes = Convert.FromBase64String(encoded);
var text = Encoding.UTF8.GetString(decodedBytes);Base64 questions and answers
Clear explanations for encoding, decoding, padding, URL-safe values, files, Unicode, APIs, and JWTs.
What is Base64 in simple terms?
Base64 is a way to represent binary bytes as text using a 64-character alphabet. It helps data travel through text-oriented formats and protocols.
Is Base64 encryption?
No. Base64 is reversible encoding and provides no secrecy. Anyone can decode it without a password or key.
Why does Base64 end with one or two equals signs?
The equals signs are optional padding characters used when the final input group does not contain a complete three bytes. Some Base64 variants omit padding.
Why is Base64 larger than the original data?
Base64 represents every three input bytes with four text characters, so it adds about 33 percent overhead before line breaks or surrounding markup.
What is Base64URL?
Base64URL is a URL-safe variant that replaces plus with hyphen and slash with underscore. Padding is commonly omitted. JWT segments use Base64URL.
Can Base64 encode images and PDF files?
Yes. Any bytes can be Base64 encoded, including images and PDFs. Large files become significantly larger, so normal binary uploads are usually more efficient.
What is a Base64 data URL?
A data URL embeds content directly in a URL-like string, for example data:image/png;base64 followed by encoded bytes. It is useful for small assets but inefficient for large files.
Does Base64 preserve Unicode text?
Base64 works with bytes, not characters. Convert Unicode text to a defined encoding such as UTF-8 before Base64 encoding, and decode the bytes using the same character encoding.
Can I put passwords or API secrets in Base64?
Base64 does not protect secrets. HTTP Basic authentication uses Base64 only as a wire format and must always be sent over HTTPS.
How is Base64 used in JWT?
JWT header and payload segments use Base64URL encoding. This makes them URL-safe and readable, but it does not encrypt their claims.
When should I avoid Base64?
Avoid Base64 for large files when the protocol already supports binary data. It increases size, memory usage, and processing work.
Is it safe to decode unknown Base64?
Decoding text is usually straightforward, but the resulting bytes may represent an unsafe file or untrusted content. Do not automatically execute, render, or open decoded data without validation.
Suggested tools


