You've probably seen long strings of random-looking characters like SGVsbG8gV29ybGQh. That's Base64 encoding. But what is it, and why do we use it?
What is Base64?
Base64 is a way to represent binary data (like images, files, or any bytes) using only 64 printable ASCII characters:
- Letters: A-Z, a-z (52 characters)
- Numbers: 0-9 (10 characters)
- Symbols: + and / (2 characters)
- Padding: = (used at the end)
Why Do We Need It?
Many systems were designed to handle only text, not binary data. Base64 solves this by converting any data into safe text characters.
Common Use Cases:
- Email attachments: Binary files encoded as text
- Data URLs: Embedding images directly in HTML/CSS
- API transfers: Sending binary data in JSON
- Storing binary in databases: When only text fields are available
- Basic authentication: Encoding username:password
How It Works (Simplified)
- Take your input data as bytes
- Group bytes into sets of 3 (24 bits)
- Split into 4 groups of 6 bits each
- Convert each 6-bit value to a Base64 character
Example:
Text: "Hi"
ASCII: 72, 105
Binary: 01001000 01101001
Split (6-bit): 010010 000110 1001xx
Base64: S G k =
Result: "SGk="
Base64 Examples
| Original | Base64 |
|---|---|
| Hello | SGVsbG8= |
| Hello World! | SGVsbG8gV29ybGQh |
| 123 | MTIz |
Important Notes
- Not encryption: Base64 is encoding, not security. Anyone can decode it.
- Size increase: Base64 is ~33% larger than the original data
- Reversible: You can always decode back to the original
- URL-safe variant: Uses - and _ instead of + and /
When NOT to Use Base64
- ❌ For security/hiding data (use encryption instead)
- ❌ For large files (increases size by 33%)
- ❌ When binary transfer is supported
Base64 in Different Languages
// JavaScript
btoa("Hello") // Encode: "SGVsbG8="
atob("SGVsbG8=") // Decode: "Hello"
# Python
import base64
base64.b64encode(b"Hello") # b'SGVsbG8='
base64.b64decode(b"SGVsbG8=") # b'Hello'
🔧 Encode & Decode Base64
Use our free tool to convert text to Base64 and back instantly.
Try Base64 Tool →