DeveloperTools
Encoding Tools

Base64 Encoding Explained: Everything You Need to Know

Understand Base64 encoding, how it works, when to use it, and common use cases in web development.

Base64 is a binary-to-text encoding scheme that represents binary data using 64 ASCII characters. It's essential for transmitting binary data over text-based protocols like HTTP, email, and JSON.

How Base64 Works

Base64 takes 3 bytes (24 bits) of input and splits them into 4 groups of 6 bits each. Each 6-bit value maps to a character: A-Z, a-z, 0-9, +, and /. The result increases data size by approximately 33%.

Common Use Cases

  • Data URIs: Embedding images in CSS/HTML using data:image/png;base64,...
  • Email attachments: MIME encoding uses Base64 for binary attachments
  • HTTP Basic Auth: Credentials are Base64-encoded in the Authorization header
  • JWT tokens: Header and payload sections are Base64URL-encoded
  • Binary data in JSON: Sending binary data through JSON APIs

Base64 vs Base64URL

Standard Base64 uses + and / which have special meaning in URLs. Base64URL replaces + with - and / with _, making it safe for URLs. JWT tokens use Base64URL encoding.

Security Note

Base64 is encoding, not encryption. It provides zero security. Never use Base64 to protect sensitive data. Use proper encryption (AES) or hashing (bcrypt, SHA-256) for security.

Frequently Asked Questions

Does Base64 increase file size?
Yes, by approximately 33%. A 100KB file becomes about 133KB when Base64-encoded.
Is Base64 reversible?
Yes, Base64 is fully reversible. You can always decode back to the original data without any loss.
Can Base64 be used for encryption?
No. Base64 is encoding, not encryption. Anyone can decode it. Use AES-256 for encryption.