Base64 Encode / Decode

Encode and decode text strings to and from Base64 format locally in your browser.

Advertisement
Modify the values and click Calculate

Base64 Encode & Decode — Binary-to-Text Encoding Guide

Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format. It is widely used across the web to transmit files, images, and other complex data over channels that are designed to handle only standard text characters.

This guide explains what Base64 is, how the encoding process works, its practical use cases, and why it should never be confused with encryption.

---

1. What Is Base64?

Historically, many communication protocols (such as SMTP for email) were designed to handle only 7-bit ASCII text. When users tried to send binary files (like images, zip archives, or audio files) through these networks, the data would often get corrupted because certain non-printable binary characters were misinterpreted by routers or servers.

Base64 solves this by translating any binary data into a safe, restricted alphabet of 64 printable ASCII characters:

  • Uppercase letters: `A` to `Z` (26 characters)
  • Lowercase letters: `a` to `z` (26 characters)
  • Digits: `0` to `9` (10 characters)
  • Symbols: `+` (plus) and `/` (slash) (2 characters)

---

2. How the Base64 Algorithm Works

The math behind Base64 is based on grouping bits. Since `2^6 = 64`, each Base64 character represents exactly 6 bits of information.

Here is the step-by-step encoding process:

1. Group by 3 Bytes: The algorithm takes 3 bytes (24 bits) of input data.

2. Split into 4 Groups: The 24 bits are split into 4 groups of 6 bits each.

3. Map to Characters: Each 6-bit binary value (ranging from 0 to 63) is translated into its corresponding character from the Base64 index.

4. Padding: If the input data is not a multiple of 3 bytes, the algorithm pads the remainder with zero bits and appends one or two `=` symbols to the end of the encoded string to signal padding to the decoder.

Example: Encoding "Man"

The ASCII values for "Man" are:

  • M = 77 (binary `01001101`)
  • a = 97 (binary `01100001`)
  • n = 110 (binary `01101110`)

Combined, these three bytes form a 24-bit stream:

`010011010110000101101110`

Splitting this into four 6-bit segments:

1. `010011` = 19 (maps to T)

2. `010110` = 22 (maps to W)

3. `000101` = 5 (maps to F)

4. `101110` = 46 (maps to u)

Encoded Result: `TWFu`

---

3. Practical Use Cases

  • Email Attachments (MIME): Email client systems use Base64 to convert attachments (images, PDFs) into text streams to append to email bodies.
  • Data URIs: Developers can embed small images directly into HTML or CSS using data URIs (e.g., ``). This eliminates the need for separate HTTP requests.
  • Web API Payloads: Simple API configurations or database keys are sometimes encoded to make them safe for XML or JSON structures.

---

4. Overhead and Limitations

Because Base64 uses 4 characters to represent 3 bytes of data, it introduces a size overhead of roughly 33%.

For example, a 75 KB image file will grow to approximately 100 KB after Base64 encoding. Because of this overhead, Base64 is not recommended for transferring very large files, as it increases bandwidth consumption and memory usage.

---

[!WARNING]
Base64 is NOT Encryption.
Base64 is an open encoding scheme. It provides zero security. Anyone can easily decode a Base64 string back to its original form using standard online tools or programming languages. Never use Base64 to store or transmit passwords, credit card numbers, or other sensitive personal data.

Related Calculators

Frequently Asked Questions

Base64 is a binary-to-text encoding scheme that translates binary data (like files or images) or Unicode strings into a set of 64 ASCII characters, allowing safe transmission over text-only protocols like email or HTTP.

Base64 is used to prevent data corruption when binary data is transmitted through systems that are designed to handle text only, or that might alter whitespace, line endings, or special characters.

Base64 increases file size by roughly 33%. Every 3 bytes of original data are converted into 4 characters of Base64 (meaning 4 bytes of ASCII text).

The character set includes 64 characters: uppercase letters (A-Z), lowercase letters (a-z), numbers (0-9), plus (+), slash (/), and the equals sign (=) used for padding at the end.

Base64URL is a URL-safe variant. It replaces the plus (+) with a minus (-), the slash (/) with an underscore (_), and omits the padding equals signs (=) to prevent URL path confusion.

You can insert Base64 images directly into the HTML src attribute: <img src="data:image/png;base64,iVBORw0KGgoAAA..." />. This is useful for embedding small icons to reduce HTTP requests.

Advertisement