SBTI Personality Test: A 15-Dimension Character Analysis Beyond MBTI
12 min
Base64 is an encoding scheme that converts binary data into ASCII text, widely used for email attachments, embedding images in HTML/CSS, and API data transfer. This guide covers everything from theory to practice.
Base64 is an encoding scheme that represents binary data using 64 printable characters: uppercase A–Z (26), lowercase a–z (26), digits 0–9 (10), plus + and / (2) — totalling 64 characters, hence the name.
This encoding was originally designed for MIME (Multipurpose Internet Mail Extensions) to safely transmit binary data (images, files) over protocols that only support ASCII text.
The core logic is a 3 bytes → 4 characters conversion:
1. Group the binary data in chunks of 3 bytes (3 × 8 = 24 bits)
2. Split each 24-bit chunk into 4 groups of 6 bits
3. Each 6-bit value (0–63) maps to a character in the Base64 alphabet
Example: encoding Man:
TWFu``css
.icon {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA...');
}
`
Pros: reduces HTTP requests — great for small icons.
Cons: encoded size is ~33% larger, so avoid for large images.
2. HTTP Basic Authentication
`
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
`
⚠️ Base64 is not encryption — it's trivially reversible. Always pair with HTTPS.
3. JWT (JSON Web Tokens)
JWTs use Base64URL (replacing + with - and / with _) for their three-part structure:
`
Header.Payload.Signature
`
4. Email Attachments
SMTP only transmits 7-bit ASCII. MIME + Base64 allows binary attachments to travel safely.
Online Base64 Tool
Need a quick encode/decode? Use our Image to Base64 tool — supports drag-and-drop for PNG, JPG, SVG, and more.
Base64 in JavaScript
`javascript
// Encode (ASCII only)
const encoded = btoa('Hello, World!'); // SGVsbG8sIFdvcmxkIQ==
// Decode
const decoded = atob('SGVsbG8sIFdvcmxkIQ=='); // Hello, World!
// For non-ASCII (e.g. Chinese characters):
const encodeChinese = btoa(unescape(encodeURIComponent('你好')));
``
A very common misconception: Base64 is encoding, not encryption.
|---|---|---|
| | Base64 | Encryption (e.g. AES) | |
| Reversible | Completely, no key needed | Requires a key |
| Purpose | Format conversion | Data security |
| Size change | +~33% | Variable padding |
Base64's core value: convert arbitrary binary data to plain text so it can flow safely through text-only channels. Understanding when and why to use it is essential knowledge for every web developer.
woshiit 技术团队
woshiit AI Navigation · Original Content
12 min
8 min
8 min
6 min