What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a string of 64 printable ASCII characters. It was designed to solve a specific problem: transmitting binary data through systems that only support text — email being the original and most important use case.
Encode and decode any text or data with WritePadPro's Base64 Encoder & Decoder — paste plain text to get the Base64 representation, or paste Base64 to decode it back to readable text.
When you attach a photo to an email, that image is binary data — sequences of bytes representing pixel colors. But email protocols (SMTP) were designed to carry 7-bit ASCII text, not arbitrary binary. Base64 converts the image's binary bytes into a safe text representation that travels through the email system, then the recipient's email client decodes it back to the original image.
The name "Base64" comes from the encoding's alphabet of 64 characters. Just as decimal uses 10 digits (0-9) and hexadecimal uses 16 (0-F), Base64 uses 64 characters: A-Z (26), a-z (26), 0-9 (10), + and / (2). These 64 characters are safe in virtually every text-based protocol and system.
How the Algorithm Works
The Base64 encoding process converts every 3 bytes of input into 4 characters of output, using a 6-bit grouping scheme.
Step 1: Convert to Binary
Take the input bytes and express them as a continuous binary stream. The text "Hi" in ASCII is two bytes: H = 72 = 01001000, i = 105 = 01101001. Combined: 01001000 01101001.
Step 2: Split Into 6-Bit Groups
Instead of the usual 8-bit byte grouping, split the binary stream into 6-bit groups: 010010 000110 1001. Since the last group has only 4 bits, pad with zeros to make 6: 010010 000110 100100.
Step 3: Map to Base64 Characters
Each 6-bit group represents a value from 0 to 63. Map each value to the Base64 alphabet:
| 6-Bit Value | Decimal | Base64 Character |
|---|---|---|
| 010010 | 18 | S |
| 000110 | 6 | G |
| 100100 | 36 | k |
Step 4: Add Padding
Base64 output must be a multiple of 4 characters. Since "Hi" produces only 3 Base64 characters (SGk), add one = padding character: SGk=
The Complete Base64 Alphabet
| Values 0-15 | Values 16-31 | Values 32-47 | Values 48-63 |
|---|---|---|---|
| 0=A, 1=B, 2=C, 3=D | 16=Q, 17=R, 18=S, 19=T | 32=g, 33=h, 34=i, 35=j | 48=w, 49=x, 50=y, 51=z |
| 4=E, 5=F, 6=G, 7=H | 20=U, 21=V, 22=W, 23=X | 36=k, 37=l, 38=m, 39=n | 52=0, 53=1, 54=2, 55=3 |
| 8=I, 9=J, 10=K, 11=L | 24=Y, 25=Z, 26=a, 27=b | 40=o, 41=p, 42=q, 43=r | 56=4, 57=5, 58=6, 59=7 |
| 12=M, 13=N, 14=O, 15=P | 28=c, 29=d, 30=e, 31=f | 44=s, 45=t, 46=u, 47=v | 60=8, 61=9, 62=+, 63=/ |
Padding Rules
- 3 bytes input → 4 Base64 characters, no padding
- 2 bytes input → 3 Base64 characters + one
= - 1 byte input → 2 Base64 characters + two
==
Padding ensures the encoded output length is always a multiple of 4, which simplifies decoding. For a comparison of how binary data is represented numerically, see our Binary & Hex Guide.
The 33% Size Overhead
Base64 encoding increases data size by approximately 33%. Every 3 bytes of input become 4 bytes of output — a 4:3 expansion ratio. A 1 MB image becomes approximately 1.33 MB when Base64 encoded.
Why the Overhead?
Each byte has 8 bits (256 possible values). Each Base64 character represents only 6 bits (64 possible values). You need more characters to encode the same information: 8 bits per byte ÷ 6 bits per character = 1.33 characters per byte.
When the Overhead Matters
- Inline images in CSS/HTML: A 10 KB icon becomes ~13.3 KB when Base64 encoded and embedded. For small images (under 5 KB), the overhead is offset by saving an HTTP request. For large images, the overhead makes Base64 embedding counterproductive.
- API payloads: Base64-encoded file uploads are 33% larger than binary uploads. Most modern APIs accept multipart/form-data (binary) to avoid this overhead.
- Email attachments: A 5 MB PDF attachment becomes ~6.7 MB after Base64 encoding. This is why email attachment limits are typically lower than the raw file size limit.
When the Overhead Does NOT Matter
- Short strings: Encoding a 32-byte API token adds only ~11 bytes — negligible.
- JWT tokens: JWT payloads are typically under 1 KB. The 33% overhead adds a few hundred bytes — irrelevant.
- Small icons: A 2 KB SVG icon becomes 2.7 KB. Saving the HTTP request is worth more than the 700 bytes.
Use Cases for Base64 Encoding
1. Email Attachments (MIME)
The original motivation for Base64 was email. SMTP (Simple Mail Transfer Protocol) was designed to carry 7-bit ASCII text. Binary files — images, PDFs, executables — cannot travel through SMTP directly. MIME (Multipurpose Internet Mail Extensions) solves this by Base64-encoding attachments into text that SMTP can transport. Every email client decodes Base64 attachments transparently — you see the image, not the encoded text.
2. Data URIs (Inline Images)
Data URIs embed Base64-encoded images directly in HTML or CSS, eliminating a separate HTTP request:
<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />This technique is best for small images (under 5 KB) — icons, logos, decorative elements. Larger images should remain as separate files because the 33% size increase and loss of browser caching outweigh the saved HTTP request. For related HTML encoding techniques, see the URL Encoder and HTML Encoder.
3. JWT (JSON Web Tokens)
JWT tokens — the standard for web authentication — use Base64url encoding (a variant that replaces + with - and / with _) for their header and payload segments. A JWT looks like: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiam9obiJ9.abc123... Each segment before the dots is a Base64url-encoded JSON object.
4. API Data Transfer
When APIs need to include binary data (images, documents, certificates) in JSON payloads, Base64 encoding converts the binary into a JSON-safe string. The receiving system decodes it back to binary. While not the most efficient method (multipart uploads are better for large files), it is simple and universally supported.
5. Storing Binary in Text Databases
Some databases and configuration systems only support text fields. Base64 allows storing small binary blobs (cryptographic keys, small images, encoded certificates) in text columns without corruption. For building and testing encoded content, see our Code Playground Guide.
6. Obfuscation (NOT Encryption)
Base64 is sometimes used to obscure data from casual inspection — encoding a password or API key so it is not immediately readable. However, Base64 is not encryption. It is trivially reversible by anyone. Never use Base64 as a security measure. It is an encoding scheme, not a cryptographic algorithm.
Base64 Variants
Several Base64 variants exist for different contexts, each modifying the standard alphabet slightly.
| Variant | Characters 62-63 | Padding | Used In |
|---|---|---|---|
| Standard (RFC 4648) | + / | = padding | Email (MIME), general use |
| URL-safe (RFC 4648 §5) | - _ | Optional | URLs, JWT, filenames |
| MIME (RFC 2045) | + / | = padding, line breaks every 76 chars | Email attachments |
| Filename-safe | - _ | No padding | Filenames, URL parameters |
Why URL-Safe Base64 Exists
Standard Base64 uses + and / characters, which have special meanings in URLs (+ means space, / is a path separator). URL-safe Base64 replaces these with - (hyphen) and _ (underscore), which are safe in URLs without percent-encoding. JWT uses URL-safe Base64 for this reason — tokens often appear in URL query parameters.
Base64 in Programming Languages
Every modern programming language provides built-in Base64 encoding and decoding functions.
| Language | Encode | Decode |
|---|---|---|
| JavaScript (browser) | btoa(string) | atob(string) |
| JavaScript (Node.js) | Buffer.from(str).toString('base64') | Buffer.from(b64, 'base64').toString() |
| Python | base64.b64encode(bytes) | base64.b64decode(string) |
| PHP | base64_encode($string) | base64_decode($string) |
| Java | Base64.getEncoder().encode(bytes) | Base64.getDecoder().decode(string) |
| C# | Convert.ToBase64String(bytes) | Convert.FromBase64String(string) |
| Go | base64.StdEncoding.EncodeToString(bytes) | base64.StdEncoding.DecodeString(str) |
| Ruby | Base64.encode64(string) | Base64.decode64(string) |
| Command line | echo -n "text" | base64 | echo "dGV4dA==" | base64 -d |
Note: JavaScript's btoa() only works with Latin-1 characters. For Unicode text, first encode to UTF-8: btoa(unescape(encodeURIComponent(text))). For related encoding guides, see our URL Encoding Guide and HTML Entities Guide.
Using WritePadPro's Base64 Encoder & Decoder
WritePadPro's Base64 Encoder & Decoder converts between plain text and Base64 instantly.
Step 1: Open the Tool
Navigate to the Base64 Encoder & Decoder. You will see an input area and encode/decode options.
Step 2: Encode Text to Base64
Paste or type your plain text. Click encode. The tool converts each character to its byte value, groups the bytes into 6-bit segments, maps to the Base64 alphabet, and adds padding. "Hello, World!" becomes SGVsbG8sIFdvcmxkIQ==
Step 3: Decode Base64 to Text
Paste a Base64 string. Click decode. The tool reverses the process: maps each character to its 6-bit value, reassembles into 8-bit bytes, and converts to text. SGVsbG8sIFdvcmxkIQ== becomes "Hello, World!"
Step 4: Verify and Use
Use the encoded output in data URIs, API payloads, JWT debugging, email troubleshooting, or any context requiring text-safe binary representation.
Privacy
All encoding and decoding runs locally in your browser using JavaScript's built-in Base64 functions. Your data is never transmitted to any server. This is especially important when decoding JWT tokens or API credentials — sensitive data should never be pasted into server-based encoding tools.
Summary
Base64 is a binary-to-text encoding that converts arbitrary data into 64 safe ASCII characters (A-Z, a-z, 0-9, +, /). It exists because many systems — email protocols, JSON, URLs, text databases — cannot handle raw binary data. The algorithm groups input bytes into 6-bit segments and maps each to a character, producing output 33% larger than the input.
Primary use cases: email attachments (MIME), data URIs for inline images, JWT tokens, API data transfer, and text-field binary storage. Base64 is an encoding scheme, not encryption — it is trivially reversible and should never be used for security.
Encode and decode with WritePadPro's Base64 Encoder & Decoder — instant conversion in your browser with complete privacy.