Base64 is one of those encoding schemes you encounter constantly in software development but rarely stop to fully understand. API authentication headers, JWT tokens, email attachments, image embedding in HTML โ Base64 is everywhere. Here's the complete picture.
What is Base64?
Base64 is a binary-to-text encoding scheme that converts binary data (bytes) into a string of 64 ASCII characters: AโZ, aโz, 0โ9, + and /. The name comes from using 64 different characters. It adds roughly 33% size overhead but ensures data can be safely transmitted through text-only channels (email, JSON, URLs) without corruption.
Why Base64 Exists
Many systems were designed to handle text only โ email (SMTP), HTTP headers, JSON, XML. Binary data (images, PDFs, executables) contains bytes that could be misinterpreted as control characters. Base64 converts binary to safe text so it can pass through any text-based system unchanged.
Common Base64 Use Cases
| Use Case | Example |
|---|---|
| HTTP Basic Auth | Authorization: Basic dXNlcjpwYXNz (base64 of "user:pass") |
| JWT Tokens | Header and payload sections are Base64url encoded |
| Inline images in HTML/CSS | src="data:image/png;base64,iVBOR..." |
| API file uploads | Send PDFs/images as Base64 strings in JSON body |
| Email attachments | MIME encoding for file attachments in emails |
| Storing binary in databases | Store images as Base64 text in VARCHAR columns |
Standard Base64 vs URL-Safe Base64
Standard Base64 uses + and / which are special characters in URLs. URL-safe Base64 replaces + with - and / with _, making it safe for use in URLs and file names without encoding. JWT tokens use URL-safe Base64.
Quick Reference: Encoding Example
Text: Hello, India!
Base64: SGVsbG8sIEluZGlhIQ==
Note the == padding at the end โ Base64 output is always a multiple of 4 characters, padded with = if needed.
Use our Base64 Encoder/Decoder to encode text, decode Base64 strings, and handle file encoding โ all client-side with zero data leaving your browser.