If you have ever inspected an email attachment, worked with data URIs in CSS, or decoded a JWT token, you have encountered Base64. It appears everywhere in modern computing — yet its purpose and mechanics are rarely explained clearly. This guide covers what Base64 is, how it works mathematically, and the most common real-world situations where you will need it.
Computers store and process everything as binary — sequences of 0s and 1s. But many communication systems were designed to handle only printable ASCII text. Email protocols, HTTP headers, and certain database fields were historically built around text and either corrupt or drop binary data. Base64 solves this by converting arbitrary binary data into a string of 64 printable characters that any text-based system can safely transmit without modification.
The name comes directly from the character set: Base64 uses exactly 64 printable ASCII characters — the uppercase letters A–Z, lowercase letters a–z, digits 0–9, and the symbols + and /. A 65th character, =, is used for padding.
Base64 encodes data by converting every 3 bytes (24 bits) of binary input into 4 Base64 characters (each representing 6 bits). Here is the process step by step:
If the input is not a multiple of 3 bytes, padding characters (= or ==) are added to make the output length a multiple of 4 characters. This is why Base64 output always ends in = or == when the input length is not divisible by 3.
Base64 encoding increases data size by approximately 33–36%. Every 3 bytes of input becomes 4 characters of output. A 1 MB image encoded in Base64 becomes approximately 1.37 MB. This overhead is the main trade-off for safe text transmission.
💡 Quick fact: The string Man (3 bytes: 77, 97, 110 in ASCII) encodes to TWFu in Base64 — exactly 4 characters, a perfect 3-to-4 conversion.
The MIME (Multipurpose Internet Mail Extensions) standard uses Base64 to encode email attachments — images, PDFs, documents — because SMTP (Simple Mail Transfer Protocol) was originally designed to carry only 7-bit ASCII text. When your email client sends a PDF, it Base64-encodes it first, then the receiving client decodes it.
Instead of linking to an external image file, you can embed an image directly in HTML or CSS using a data URI. The format is: data:[mediatype];base64,[encoded-data]. For example: data:image/png;base64,iVBORw0KGgo.... This eliminates an HTTP request but increases file size.
When a server requires Basic Authentication, the browser sends credentials as Authorization: Basic [base64-encoded username:password]. It is critical to understand that Base64 is not encryption — anyone who intercepts the header can decode it instantly. Basic Auth must always be used over HTTPS.
JWTs consist of three Base64URL-encoded parts separated by dots: header, payload, and signature. Base64URL is a variant that replaces + with - and / with _ to make tokens URL-safe. You can decode any JWT's header and payload at jwt.io — the data is not encrypted, only encoded.
REST APIs frequently return binary data — images, audio clips, generated PDFs — as Base64 strings in JSON responses, since JSON cannot contain raw binary. The client decodes the string back to binary before use.
SSL/TLS certificates, RSA public keys, and cryptographic hashes are commonly stored and transmitted in Base64-encoded PEM (Privacy Enhanced Mail) format — the text blocks that start with -----BEGIN CERTIFICATE-----.
This is the most important point. Base64 is an encoding scheme — a reversible transformation between binary and text. It provides zero security. Anyone with the encoded string and knowledge of Base64 (which is public) can decode it in milliseconds. Never use Base64 to protect sensitive data. Use it only for safe transmission of binary over text channels, and combine with actual encryption (AES, RSA) when security is needed.
| Variant | Characters 62 and 63 | Padding | Use Case |
|---|---|---|---|
| Standard (RFC 4648) | + and / | Yes (=) | Email, file encoding |
| Base64URL (RFC 4648 §5) | - and _ | Optional | JWTs, URL parameters |
| MIME (RFC 2045) | + and / | Yes | Email MIME encoding |
Our free Base64 tool encodes any text to Base64 or decodes any Base64 string — entirely in your browser.
Open Base64 Tool →