← Back to Blog
base64encodingweb developmentdeveloper tools

What is Base64 and What is it Used For?

By QuickyTools  ·  Published on

What is Base64?

Base64 is an encoding scheme that converts binary data into a string of printable ASCII characters. It represents binary data using a set of 64 characters: the 26 uppercase letters (A–Z), 26 lowercase letters (a–z), 10 digits (0–9), and the symbols + and /. The = character is used for padding.

The name “Base64” refers to this set of 64 characters. Each Base64 character represents exactly 6 bits of binary data.

How the encoding works

Binary data is processed in groups of 3 bytes (24 bits). Each group is split into four 6-bit chunks, and each chunk maps to a Base64 character. This means:

  • Every 3 bytes of input become 4 Base64 characters
  • Base64-encoded data is ~33% larger than the original binary

If the input is not divisible by 3, = padding characters are added at the end.

Example:

HelloSGVsbG8=

Why Does Base64 Exist?

Many systems and protocols were originally designed to handle text only — not arbitrary binary data. Email protocols (SMTP), XML, JSON, and HTML all work with text. But images, audio files, and other binary data need to be transmitted alongside text in these contexts.

Base64 solves this by converting binary into a text-safe representation that can travel through any text-based system without corruption.

Common Use Cases

1. Embedding images in HTML/CSS

Instead of linking to an external file, you can embed an image directly:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUh..." />
background-image: url('data:image/png;base64,iVBORw0K...');

This is useful for small icons or critical images that you don’t want to require a separate HTTP request.

2. Email attachments

The MIME standard uses Base64 to encode file attachments in emails. The binary file data is converted to Base64 text and included in the email body, then decoded by the recipient’s email client.

3. JSON and API payloads

REST APIs and JSON payloads are text-based. When you need to include binary data (like an image or file) in a JSON request, Base64 encoding is the standard approach:

{
  "filename": "photo.jpg",
  "data": "iVBORw0KGgoAAAANSUh..."
}

4. Authentication tokens

HTTP Basic Authentication encodes the username and password in Base64:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Note: Base64 is not encryption — it’s trivially reversible. This is why HTTPS is required when using Basic Auth.

5. Data URIs in SVG and Canvas

When working with the HTML5 Canvas API or generating SVGs programmatically, exporting to a data URI produces a Base64-encoded string that can be directly assigned to image sources or download links.

6. Storing binary data in databases

Some older databases or configurations only support text fields. Binary data (like profile images) can be stored as Base64 strings in these cases.

Base64 is NOT Encryption

This is a critical point: Base64 encodes, it does not encrypt. Anyone can decode a Base64 string in seconds. Never use Base64 to hide sensitive information like passwords or private data. Use proper encryption (AES, RSA) for that purpose.

URL-Safe Base64

Standard Base64 uses + and / characters which have special meanings in URLs. For URLs and filenames, a variant called Base64url replaces + with - and / with _. Many modern systems (JWT tokens, for example) use this variant.

Encode and Decode Base64 Instantly

Our free Base64 Encoder/Decoder handles both text and file encoding, fully in your browser with no data sent to any server.