Base64 Files
Beginner's Guide

What Is Base64?

Base64 is an encoding scheme that converts binary data into printable ASCII text. It is not encryption and not compression — it simply changes the representation of data so binary content can be safely transmitted through text-only systems.

Try It

Text → Base64

Base64

13 chars → 20 Base64 chars (+54%)

Base64 → Text

Decoded text

What Is Base64

Base64 is a binary-to-text encoding scheme defined by RFC 4648. Its name comes from its use of 64 printable ASCII characters (A–Z, a–z, 0–9, +, /) to represent any binary data.

Base64 is not encryption and not compression. Anyone can decode a Base64 string with a single function call — no key or secret required. Its only job is converting binary to text — convenient for transport, not for privacy.

Analogy: Imagine you need to send a paper map through a text-only channel. You could redescribe every point on the map as latitude/longitude coordinates — the content is unchanged, just reformatted so it can be transmitted. Base64 does the same thing with binary data.

Why Base64 Was Invented

Early email protocols (SMTP) and many network protocols were designed to carry only 7-bit ASCII text. Binary data (images, files) contains arbitrary bytes with values 0–255; many of those bytes have special meanings in these protocols (line endings, terminators, control characters), so transmitting them directly corrupts the content.

Base64 solves this by using only 64 “safe” ASCII characters, ensuring encoded data can be transmitted unchanged through any text-based protocol. Its most common uses today include:

How Base64 Works

Raw file / text

Binary data

Binary bytes

01001101 01100001…

Base64 encoding

3 bytes → 4 chars

Plain-text string

TWFu… (safe to transmit)

The encoding process has three steps:

  1. 1
    Take 3 bytes (24 bits): Read 3 bytes at a time from the input and combine them into a single 24-bit number.
  2. 2
    Split into 4 groups of 6 bits: Divide the 24 bits evenly into 4 groups of 6 bits each. Six bits can represent 64 distinct values (2⁶ = 64).
  3. 3
    Map to characters: Use each 6-bit value (0–63) to look up the corresponding character in the Base64 alphabet. Three bytes become four characters.

Example: how the string Man is encoded as TWFu

Input charMan
ASCII bytes010011010110000101101110
6-bit groups010011010110000101101110
Decimal index1922546
Base64 charTWFu

3 bytes (24 bits) → 4 Base64 characters = ×4/3, roughly 33% larger

The Base64 Alphabet

Standard Base64 (RFC 4648) uses these 64 characters, plus = as a padding character:

A–Z

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Value 0–25

a–z

abcdefghijklmnopqrstuvwxyz

Value 26–51

0–9

0123456789

Value 52–61

+ /

+/

Value 62–63

Base64URL variant (used for JWT and URLs) replaces + with -, replaces / with _, and omits = padding to avoid ambiguity in URLs and query strings.

Real-World Examples

Plain text

Original

Hello, World!

Base64

SGVsbG8sIFdvcmxkIQ==

The trailing == is padding because 13 bytes is not a multiple of 3

Data URL (inline image)

Original

<img src="data:image/png;base64,iVBORw0KGgo…">

Base64

CSS: background-image: url("data:image/png;base64,…")

Written directly in HTML/CSS — no extra HTTP request needed

JWT Payload (Base64URL)

Original

{"sub":"1234567890","name":"Alice","iat":1516239022}

Base64

eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFsaWNlIiwiaWF0IjoxNTE2MjM5MDIyfQ

No = padding; + and / replaced by - and _ (Base64URL)

HTTP Basic Auth

Original

username:password

Base64

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Encoding only, not encryption — always pair with HTTPS

Limitations of Base64

Roughly 33% size increase

Every 3 bytes become 4 characters, so the encoded output is about 1.33× the original size. Not suitable for large files.

Not encryption

Base64 does not protect data. Anyone can decode it with one line of code. Use real encryption for sensitive data.

Can freeze the browser with large files

FileReader.readAsDataURL() processes the full file on the main thread — a 10 MB file can make the page unresponsive.

No streaming support

Standard Base64 requires the complete data before encoding or decoding. It does not support chunked or streaming processing.

Related Tools

FAQ

What is Base64?

Base64 is a scheme for encoding binary data as printable ASCII text, using 64 characters (A–Z, a–z, 0–9, +, /) to represent any binary content. It lets binary data travel safely through text-only protocols.

Is Base64 encryption?

No. Base64 is encoding, not encryption. There is no key — anyone can decode it in one line. Do not use Base64 to protect sensitive data.

Why does Base64 make files larger?

Base64 encodes 3 bytes as 4 characters (1 byte each), making the output 4/3 of the original — roughly 33% larger. This is the unavoidable cost of representing binary as text.

What is the difference between Base64 and Base64URL?

Base64URL is the URL-safe variant: it replaces + with -, replaces / with _, and omits = padding. This means the encoded string can be placed directly in a URL or query string without misinterpretation. JWT uses Base64URL.

When should I use Base64?

When you need to pass binary data through a text-only channel — e.g., small images inlined in CSS/HTML, file attachments in JSON APIs, or images in HTML email. For large files or server uploads, use multipart/form-data.

How do I encode and decode Base64 in JavaScript?

Browsers have built-in btoa() (encode) and atob() (decode). These only handle Latin-1 characters; for Unicode or emoji, first convert with TextEncoder, then encode. Reverse with TextDecoder when decoding. In Node.js, use Buffer.from(str).toString('base64') and Buffer.from(b64, 'base64').toString('utf8').