šŸ””
Developer Tools
February 22, 20267 min readBy SoftStash Team

What is Base64 Encoding? A Complete Guide with Examples

Learn what Base64 encoding is, why it exists, where it's used, and how to encode and decode Base64 strings instantly in your browser — no tools to install.

base64encodingdeveloperbinarydata formats

Open any modern web application, inspect an HTTP request, glance at a Kubernetes manifest, or peek inside a JWT token — Base64 is everywhere. It is one of those foundational encoding schemes that developers encounter constantly yet rarely stop to fully understand. This guide explains what Base64 is, how it works at the byte level, where it is used in real-world systems, and when you should (and should not) reach for it.

You can encode and decode any Base64 string instantly using the SoftStash Base64 Encoder/Decoder — free, no sign-up, and nothing ever leaves your browser.

Why Does Base64 Exist?

To understand Base64, you need to understand the problem it solves. In the early days of the internet, many communication protocols — particularly email — were designed around 7-bit ASCII text. ASCII defines 128 characters using 7 bits per character. Binary data (images, documents, executables) uses all 8 bits per byte, producing byte values that had no ASCII representation and that older systems would discard, mangle, or interpret as control commands.

The MIME (Multipurpose Internet Mail Extensions) standard, introduced in 1991 to allow email to carry attachments, needed a way to transmit arbitrary binary data through these 7-bit-clean channels. The solution was to re-encode binary data using only a safe subset of printable ASCII characters — one that every system agreed on and would transmit faithfully. Base64 became the standard encoding for this purpose, and the name describes the approach: use a set of 64 safe characters to represent any binary data.

The 64-Character Alphabet

Base64 uses exactly 64 characters, which is why 6 bits of input can always be represented by one Base64 character (26 = 64). The standard alphabet defined in RFC 4648 is:

  • Uppercase letters A through Z — values 0 to 25
  • Lowercase letters a through z — values 26 to 51
  • Digits 0 through 9 — values 52 to 61
  • + — value 62
  • / — value 63

A 65th character — the equals sign = — is used as padding but does not represent data. Padding ensures that the encoded output length is always a multiple of 4 characters, which simplifies decoding.

How Base64 Encoding Works: 3 Bytes → 4 Characters

Base64 works by taking 3 bytes of input (24 bits) and splitting them into four 6-bit groups. Each 6-bit group maps to one character in the Base64 alphabet. Because 3 bytes become 4 characters, Base64 encoding increases the size of the data by exactly one third (33%).

Let us walk through a concrete example: encoding the ASCII string "Man".

Step 1 — Convert each character to its ASCII byte value and then to binary:

  • M = ASCII 77 = 01001101
  • a = ASCII 97 = 01100001
  • n = ASCII 110 = 01101110

Step 2 — Concatenate the 24 bits into one stream:

01001101 01100001 01101110
↓ (concatenate all 24 bits)
010011 010110 000101 101110

Step 3 — Map each 6-bit group to the Base64 alphabet:

6-bit groupDecimal valueBase64 character
01001119T
01011022W
0001015F
10111046u

The Base64 encoding of "Man" is TWFu. You can verify this using the SoftStash Base64 tool. When the input length is not a multiple of 3, padding characters (= or ==) are appended to bring the output to a multiple of 4 characters. For example, "Ma" encodes to TWE= and "M" encodes to TQ==.

Common misconception: Base64 is encoding, not encryption. The process is completely reversible by anyone without any key or password. Seeing Base64-encoded data in a URL, header, or file does not mean that data is protected in any way — it is simply a different representation of the same bytes. Anyone who can copy the string can decode it instantly.

Common Use Cases

Embedding Images in HTML and CSS

Rather than making a separate HTTP request for a small image or icon, you can embed it directly in your HTML or CSS as a data URI. The browser decodes the Base64 string and renders the image without a network round-trip. This is useful for small assets like favicons, loading spinners, or inline icons in email templates where external URL loading may be blocked.

/* CSS example — embedding a small PNG icon */
.icon {
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...');
}

Binary Data in JSON APIs

JSON is a text format. If an API needs to transmit binary data — a file, a cryptographic key, a signature, an image — inside a JSON payload, it cannot include raw bytes. Base64-encoding the binary data turns it into a plain string that JSON can carry without issue. Many APIs that return file content, audio samples, or images in JSON responses use this approach.

HTTP Basic Authentication

The HTTP Basic Auth scheme sends credentials in the Authorization header as a Base64 encoding of username:password. For example, the credentials admin:secret become the string YWRtaW46c2VjcmV0, and the full header looks like:

Authorization: Basic YWRtaW46c2VjcmV0

This is not encrypted — it is just encoded. Basic Auth must always be used over HTTPS, never over plain HTTP, because the credentials can be decoded trivially by anyone who intercepts the request.

JWT Payloads

JSON Web Tokens encode their header and payload using Base64URL (a URL-safe variant described below). The token's claims — user ID, expiry time, roles — are stored in the payload as a Base64URL-encoded JSON object. Again, this is not encryption: the payload is fully readable by anyone who has the token.

Kubernetes Secrets

Kubernetes stores Secret values as Base64-encoded strings in YAML manifests. Here is a real example of a Kubernetes Secret:

apiVersion: v1
kind: Secret
metadata:
  name: db-credentials
type: Opaque
data:
  username: YWRtaW4=
  password: cGFzc3dvcmQxMjM=

To find out what those values actually are, paste YWRtaW4= into the SoftStash Base64 Decoder. The result is admin. Paste cGFzc3dvcmQxMjM= and you get password123. Kubernetes Base64-encodes secret values for safe YAML formatting, not for security — the actual security comes from Kubernetes RBAC and at-rest encryption, not from the encoding itself.

The Base64URL Variant

Standard Base64 uses two characters that are special in URLs: + (which means space in form encoding) and / (which is a path separator). When Base64-encoded data needs to appear in a URL, query parameter, or filename, these characters cause problems.

Base64URL solves this by substituting:

  • + is replaced with - (hyphen)
  • / is replaced with _ (underscore)
  • Trailing = padding is often omitted

Base64URL is used in JWTs, OAuth tokens, and any context where the encoded string must survive URL transmission without percent-encoding. The SoftStash Base64 tool supports both standard and URL-safe variants.

When NOT to Use Base64

Base64 is the right tool in specific situations, but it is frequently misused. Here is when you should avoid it:

  • Large files: Base64 increases data size by ~33%. A 10 MB image becomes roughly 13.3 MB when Base64-encoded. Embedding large files as data URIs or Base64 strings in JSON slows down parsing, increases memory usage, and wastes bandwidth. Use direct file transfers or object storage URLs for anything non-trivial in size.
  • Security: Never use Base64 as a security measure. It provides zero confidentiality. If data is sensitive, use actual encryption (AES-GCM, RSA, etc.).
  • Storage: Storing binary data as Base64 in a database column wastes 33% more space compared to storing the raw bytes in a binary column. Use database-native binary types (BYTEA in PostgreSQL, BLOB in MySQL) when storing binary data at scale.

Base64 vs Hex Encoding: A Comparison

PropertyBase64Hex (Base16)
Character setA–Z, a–z, 0–9, +, / (64 chars)0–9, a–f (16 chars)
Size overhead~33% larger~100% larger (2 chars per byte)
Human readabilityLow — not recognizableModerate — byte-level legible
Common use casesEmail attachments, JWT, data URIs, API payloadsCryptographic hashes, checksums, color codes, MAC addresses
URL-safe?Only with Base64URL variantYes — all characters are URL-safe
Bits per character6 bits4 bits

Use Base64 when you need compact binary-to-text encoding and character set breadth does not create problems. Use hex when human inspection of individual byte values matters — hash digests, checksums, and cryptographic outputs are traditionally displayed in hex precisely because each hex character maps directly to 4 bits, making byte boundaries trivially visible.

Encoding and Decoding Base64 in Code

Most languages provide built-in Base64 support. Here are quick one-liners for common environments:

// JavaScript (browser or Node.js)
btoa("Hello, World!")         // → "SGVsbG8sIFdvcmxkIQ=="
atob("SGVsbG8sIFdvcmxkIQ==") // → "Hello, World!"

# Python
import base64
base64.b64encode(b"Hello, World!")         # → b'SGVsbG8sIFdvcmxkIQ=='
base64.b64decode(b"SGVsbG8sIFdvcmxkIQ==") # → b'Hello, World!'

# Bash
echo -n "Hello, World!" | base64
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode

For quick ad-hoc encoding or decoding without writing any code, the SoftStash Base64 tool is the fastest option — paste your string, choose encode or decode, and the result appears instantly. Nothing is sent to a server.

Privacy guarantee: The SoftStash Base64 encoder and decoder processes everything locally in your browser using JavaScript. If you are encoding sensitive data — API keys, secrets, private configuration — it never touches a server. Your data stays on your device.

Encode and Decode Base64 Instantly

Whether you are decoding a Kubernetes secret, inspecting a JWT payload, creating a data URI for an inline image, or just curious what a Base64 string contains — the SoftStash Base64 Encoder/Decoder handles it in a single click. Paste your input, get your output. No ads, no sign-up, no data leaving your device.

Free Base64 Encoder / Decoder — Runs 100% in Your Browser

Open Base64 Tool →

šŸ› ļø

Try the Tools — 100% Free, No Sign-Up

Everything runs in your browser. No uploads. No accounts. No ads.

Explore All Tools →