What Is Base64?
Base64 is an encoding scheme that converts binary data into printable ASCII text. It is not encryption and not compression — it simply changes the representation of data so binary content can be safely transmitted through text-only systems.
Try It
Text → Base64
13 chars → 20 Base64 chars (+54%)
Base64 → Text
What Is Base64
Base64 is a binary-to-text encoding scheme defined by RFC 4648. Its name comes from its use of 64 printable ASCII characters (A–Z, a–z, 0–9, +, /) to represent any binary data.
Base64 is not encryption and not compression. Anyone can decode a Base64 string with a single function call — no key or secret required. Its only job is converting binary to text — convenient for transport, not for privacy.
Analogy: Imagine you need to send a paper map through a text-only channel. You could redescribe every point on the map as latitude/longitude coordinates — the content is unchanged, just reformatted so it can be transmitted. Base64 does the same thing with binary data.
Why Base64 Was Invented
Early email protocols (SMTP) and many network protocols were designed to carry only 7-bit ASCII text. Binary data (images, files) contains arbitrary bytes with values 0–255; many of those bytes have special meanings in these protocols (line endings, terminators, control characters), so transmitting them directly corrupts the content.
Base64 solves this by using only 64 “safe” ASCII characters, ensuring encoded data can be transmitted unchanged through any text-based protocol. Its most common uses today include:
- Embedding images and fonts in HTML/CSS (Data URL)
- Sending file attachments in JSON APIs
- Inlining images in HTML email (many clients block binary attachments inline)
- Encoding JWT payload (Base64URL variant)
- Encoding username:password for HTTP Basic Auth
- Storing binary data inside XML or JSON
How Base64 Works
Raw file / text
Binary data
Binary bytes
01001101 01100001…
Base64 encoding
3 bytes → 4 chars
Plain-text string
TWFu… (safe to transmit)
The encoding process has three steps:
- 1Take 3 bytes (24 bits): Read 3 bytes at a time from the input and combine them into a single 24-bit number.
- 2Split into 4 groups of 6 bits: Divide the 24 bits evenly into 4 groups of 6 bits each. Six bits can represent 64 distinct values (2⁶ = 64).
- 3Map to characters: Use each 6-bit value (0–63) to look up the corresponding character in the Base64 alphabet. Three bytes become four characters.
Example: how the string Man is encoded as TWFu
| Input char | M | a | n | |
|---|---|---|---|---|
| ASCII bytes | 01001101 | 01100001 | 01101110 | |
| 6-bit groups | 010011 | 010110 | 000101 | 101110 |
| Decimal index | 19 | 22 | 5 | 46 |
| Base64 char | T | W | F | u |
3 bytes (24 bits) → 4 Base64 characters = ×4/3, roughly 33% larger
The Base64 Alphabet
Standard Base64 (RFC 4648) uses these 64 characters, plus = as a padding character:
A–Z
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Value 0–25
a–z
abcdefghijklmnopqrstuvwxyz
Value 26–51
0–9
0123456789
Value 52–61
+ /
+/
Value 62–63
Base64URL variant (used for JWT and URLs) replaces + with -, replaces / with _, and omits = padding to avoid ambiguity in URLs and query strings.
Real-World Examples
Plain text
Original
Hello, World!Base64
SGVsbG8sIFdvcmxkIQ==The trailing == is padding because 13 bytes is not a multiple of 3
Data URL (inline image)
Original
<img src="data:image/png;base64,iVBORw0KGgo…">Base64
CSS: background-image: url("data:image/png;base64,…")Written directly in HTML/CSS — no extra HTTP request needed
JWT Payload (Base64URL)
Original
{"sub":"1234567890","name":"Alice","iat":1516239022}Base64
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFsaWNlIiwiaWF0IjoxNTE2MjM5MDIyfQNo = padding; + and / replaced by - and _ (Base64URL)
HTTP Basic Auth
Original
username:passwordBase64
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=Encoding only, not encryption — always pair with HTTPS
Limitations of Base64
Roughly 33% size increase
Every 3 bytes become 4 characters, so the encoded output is about 1.33× the original size. Not suitable for large files.
Not encryption
Base64 does not protect data. Anyone can decode it with one line of code. Use real encryption for sensitive data.
Can freeze the browser with large files
FileReader.readAsDataURL() processes the full file on the main thread — a 10 MB file can make the page unresponsive.
No streaming support
Standard Base64 requires the complete data before encoding or decoding. It does not support chunked or streaming processing.
Related Tools
Text to Base64
Encode any text as Base64, Base64URL, or a Data URI.
Base64 to Text
Decode a Base64 string back to UTF-8 or ASCII text.
File to Base64
Convert any file to a Base64 string with multiple output formats.
Base64 Size Calculator
Estimate the Base64-encoded size before you convert.
Base64URL Encoder
Encode and decode URL-safe Base64URL for JWT and Web APIs.
Base64 vs URL Encoding
Understand the difference between Base64, Base64URL, and percent-encoding.
FAQ
What is Base64?
Base64 is a scheme for encoding binary data as printable ASCII text, using 64 characters (A–Z, a–z, 0–9, +, /) to represent any binary content. It lets binary data travel safely through text-only protocols.
Is Base64 encryption?
No. Base64 is encoding, not encryption. There is no key — anyone can decode it in one line. Do not use Base64 to protect sensitive data.
Why does Base64 make files larger?
Base64 encodes 3 bytes as 4 characters (1 byte each), making the output 4/3 of the original — roughly 33% larger. This is the unavoidable cost of representing binary as text.
What is the difference between Base64 and Base64URL?
Base64URL is the URL-safe variant: it replaces + with -, replaces / with _, and omits = padding. This means the encoded string can be placed directly in a URL or query string without misinterpretation. JWT uses Base64URL.
When should I use Base64?
When you need to pass binary data through a text-only channel — e.g., small images inlined in CSS/HTML, file attachments in JSON APIs, or images in HTML email. For large files or server uploads, use multipart/form-data.
How do I encode and decode Base64 in JavaScript?
Browsers have built-in btoa() (encode) and atob() (decode). These only handle Latin-1 characters; for Unicode or emoji, first convert with TextEncoder, then encode. Reverse with TextDecoder when decoding. In Node.js, use Buffer.from(str).toString('base64') and Buffer.from(b64, 'base64').toString('utf8').