What Is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data — bytes — as a string of 64 printable ASCII characters: A–Z, a–z, 0–9, +, and /. The name comes from the 64-character alphabet used. A 65th character, =, is used as padding.
The need for Base64 arose from a fundamental constraint in data transmission: many protocols (email, HTTP headers, URLs, XML) were designed to handle text only — specifically printable ASCII characters. Binary data (images, files, encrypted bytes, compiled code) contains byte values that don't map to printable characters and can be misinterpreted or corrupted when passed through text-only channels.
Base64 solves this by encoding every 3 bytes of binary data into 4 printable ASCII characters — a 33% size overhead that guarantees safe transmission through any text-based protocol.
How Base64 Encoding Works
The algorithm takes 3 input bytes (24 bits) and splits them into four 6-bit groups. Each 6-bit value (0–63) maps to a character in the Base64 alphabet:
Input bytes: M a n
Binary: 01001101 01100001 01101110
6-bit split: 010011 010110 000101 101110
Base64 index: 19 22 5 46
Base64 char: T W F u
Result: TWFu
If the input isn't divisible by 3, padding characters (= or ==) are appended to the output to signal how many bytes were in the final incomplete group.
Common Uses for Base64 Encoding
HTTP Basic Authentication
The HTTP Basic Auth scheme transmits credentials as Authorization: Basic {base64(username:password)}. The colon-separated username and password are Base64-encoded before being sent in the header. This is why decoding a Basic Auth header reveals credentials in plain text — Base64 provides no security, it just satisfies the HTTP header's ASCII-only requirement.
# Example
echo -n "user:password123" | base64
# Output: dXNlcjpwYXNzd29yZDEyMw==
# This is visible to anyone who can see the request!
Embedding Images in HTML and CSS
Small images (icons, logos) are sometimes embedded directly in HTML or CSS as Base64 data URIs to eliminate HTTP requests:
<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />
This trades file size (Base64 adds ~33% overhead) for eliminating a network round trip. Useful for critical above-the-fold images in performance-optimised pages.
Email Attachments (MIME)
Email protocols (SMTP) transmit text. File attachments are Base64-encoded into the email body using MIME encoding. When your email client shows you a PDF attachment, it decoded the Base64 data from the raw email text.
JWT Tokens
JSON Web Tokens use URL-safe Base64 (replaces + with - and / with _, omits padding) to encode the header and payload sections. The eyJ prefix you see on JWTs is the Base64-encoded opening {" of a JSON object:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
→ {"alg":"HS256","typ":"JWT"}
This is why you should never store sensitive data in a JWT payload without additional encryption — the payload is Base64, which anyone can decode.
Storing Binary Data in JSON and XML
JSON and XML represent text. Embedding binary data (file contents, encrypted blobs, compiled binaries) requires encoding to text first. Base64 is the standard approach. REST APIs that return images or files often wrap them in "data": "base64string..." JSON fields.
API Keys and Secrets Transmission
Many services transmit API keys and configuration values as Base64 strings in headers or environment variables. This makes them URL-safe and prevents whitespace/newline issues. Use our Base64 decoder to inspect the raw value when debugging API integrations.
Base64 Is NOT Encryption — This Is Critical
This misconception causes real security vulnerabilities. Base64 encoding is completely reversible without any key or password. It is a public, standardised algorithm. Anyone who sees a Base64 string can decode it in seconds — it's a one-way transformation only in the sense that it changes the representation, not the underlying information.
Do not use Base64 as a security measure for sensitive data. It provides zero confidentiality. For actually securing data:
- Symmetric encryption: AES-256-GCM
- Asymmetric encryption: RSA-OAEP, ECDH
- Password hashing: Argon2id, bcrypt
- Data in transit: TLS 1.3
Base64 is often used alongside encryption (to transport encrypted bytes through text channels) but never instead of it.
Using the Base64 Tool
The free Base64 encoder/decoder supports:
- Text encode/decode — paste plain text, get Base64 back, and vice versa
- URL-safe mode — uses
-_instead of+/for JWT and URL use cases - File encoding — drag a file to encode its binary content as Base64
- Copy-to-clipboard — one-click copy of output
Everything runs in your browser's JavaScript engine using the native btoa() / atob() functions. Nothing is transmitted to any server.
Base64 in Code — Quick Reference
# Python
import base64
encoded = base64.b64encode(b"Hello World").decode() # SGVsbG8gV29ybGQ=
decoded = base64.b64decode("SGVsbG8gV29ybGQ=").decode() # Hello World
# Node.js
const enc = Buffer.from("Hello World").toString('base64') // SGVsbG8gV29ybGQ=
const dec = Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString() // Hello World
# Browser JS
const enc = btoa("Hello World") // SGVsbG8gV29ybGQ=
const dec = atob("SGVsbG8gV29ybGQ=") // Hello World
# Bash / terminal
echo -n "Hello World" | base64 # SGVsbG8gV29ybGQ=
echo "SGVsbG8gV29ybGQ=" | base64 --decode # Hello World
Related Developer Tools
- URL Encoder/Decoder — percent-encode strings for safe use in URLs
- Hash Generator — compute SHA-256, SHA-512, MD5 in-browser
- JSON Formatter — validate and prettify JSON responses from APIs
- Password Generator — generate cryptographically secure random passwords