Base64 Encoding Explained: What It Is and When to Use It

A developer-friendly guide to Base64 encoding, decoding, and use cases.

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string. It uses 64 characters: A-Z, a-z, 0-9, +, /.

How Does Base64 Work?

  1. Take 3 bytes (24 bits).
  2. Split into 4 groups of 6 bits.
  3. Map each group to a Base64 character.
  4. Pad with = if needed.

Common Use Cases

  • Inline Images: Embed small images in CSS as data URLs.
  • Email: SMTP is text-only, so attachments use Base64 (RFC 2045).
  • JSON APIs: Transport binary payloads.
  • Basic Auth: HTTP Basic Auth headers use Base64.

Base64 vs Encryption

Base64 is NOT encryption. It is reversible instantly. For security, use AES or similar.

Example in JavaScript

// Encode
const e = btoa("Hello World"); // "SGVsbG8gV29ybGQ="
// Decode
const d = atob("SGVsbG8gV29ybGQ="); // "Hello World"

FAQ

Does Base64 increase file size?

Yes, by ~33%. 3 bytes become 4 characters.

Is Base64 safe for sensitive data?

No. Easily reversible, zero encryption. Never store passwords in Base64 alone.

When to avoid Base64?

Avoid for large files; increases payload size significantly.

Further Reading


Avatar

Muhamad Satria | Sardev Studio

CEO / Co-Founder

Hayattaki küçük şeylerden keyif al. Bir gün geriye dönüp baktığınızda bunların büyük şeyler olduğunu anlayabilirsiniz. Hayattaki başarısızlıkların çoğu, pes ettiklerinde başarıya ne kadar yakın olduklarını fark etmeyen insanlardır.