โ† Back to Blog

What Is Base64 Encoding? Explained

2026-04-01 ยท 5 min read

Introduction to Base64 Encoding

Base64 is an encoding scheme that converts binary data into a plain ASCII text representation. It uses 64 printable characters โ€” Aโ€“Z, aโ€“z, 0โ€“9, plus (+) and slash (/) โ€” to represent any binary data, hence the name "Base64". This encoding is widely used in internet protocols to safely transmit binary content over text-only media.

Before Base64, sending images or files through email was difficult because early mail systems only handled 7-bit ASCII text. Base64 solved this fundamental problem by allowing binary files to be transmitted and stored just like plain text.

The Base64 Character Set

The standard Base64 alphabet consists of 65 characters: 26 uppercase letters (Aโ€“Z), 26 lowercase letters (aโ€“z), 10 digits (0โ€“9), plus sign (+), forward slash (/), and the equals sign (=) used for padding. Each character represents a 6-bit value (2โถ = 64).

The choice of these 64 characters was deliberate โ€” they are the most universally safe printable characters across various transmission systems and character encoding standards. Every character has a corresponding value in the ASCII table, making Base64 data reliably transmittable across any standard text system.

Encoding Principle: Grouping and Mapping

The core principle of Base64 encoding is taking every 3 bytes (24 bits) of input data, splitting them into 4 groups of 6 bits each, then mapping each 6-bit group to a Base64 character. As a result, 3 bytes of raw data become 4 Base64 characters โ€” a size increase of approximately 33%.

For example, the string "Man" has ASCII values 77, 97, 110, corresponding to binary 01001101 01100001 01101110. Splitting these 24 bits into 6-bit groups gives 010011, 010110, 000101, 101110, which are decimal 19, 22, 5, 46, mapping to Base64 characters T, W, F, u โ€” the encoded result is "TWFu".

Input:  M        a        n
ASCII:  77       97       110
Binary: 01001101 01100001 01101110
6-bit:  010011 | 010110 | 000101 | 101110
Index:  19       22       5        46
Base64: T        W        F        u
Output: TWFu

The Role of Padding

When the input data's byte count is not a multiple of 3, Base64 uses the equals sign (=) for padding to ensure the output length is always a multiple of 4. If 1 byte remains, two padding characters are added; if 2 bytes remain, one padding character is added.

The presence of padding characters allows decoders to accurately determine the byte boundaries of the original data and correctly restore it. In some applications such as URL-safe Base64, padding can be omitted, but decoding requires additional handling logic.

Primary Use Cases of Base64

Base64 is widely used across many domains. In email, the MIME standard uses Base64 to encode attachments (images, PDFs, and other binary files). In web development, Data URIs allow images and fonts to be embedded directly in HTML or CSS, reducing HTTP requests. In API authentication, HTTP Basic Auth uses Base64 to encode usernames and passwords.

Additionally, JSON Web Tokens (JWT) use Base64URL (a variant) to encode their header and payload. TLS/SSL certificates are stored in PEM format, where certificate data is Base64 encoded. Cryptographic keys and binary configuration data are also frequently stored as Base64 in configuration files.

Base64 Is Not Encryption

This is the most important point about Base64: it is encoding, not encryption. It has no key, and anyone can decode a Base64 string. The purpose of Base64 is to change the representation of data for transmission purposes, not to protect data confidentiality. If you need to protect data, use real encryption algorithms like AES or RSA.

Confusing Base64 with encryption is a common security misconception. In HTTP Basic Auth, usernames and passwords are merely Base64 encoded, meaning without HTTPS protection, an attacker can easily decode the credentials. This is why all APIs using HTTP Basic Auth must be transmitted over HTTPS.

Variants of Base64

As use cases expanded, several important Base64 variants emerged. Base64URL replaces + with - and / with _, making the encoded result safe to use in URLs and filenames without percent-encoding. This is widely adopted in JWT, OAuth tokens, and similar scenarios.

Another common variant is Modified Base64 for IMAP, which replaces / with a comma (,) to avoid conflicts with the IMAP protocol's path separator. Different application scenarios may have different requirements for Base64, and choosing the correct variant is critical for system compatibility.

Summary

Base64 encoding is a standard method for converting binary data to text by mapping every 3 bytes to 4 ASCII characters. It provides no security protection but solves the fundamental problem of transmitting binary data in text-based systems. Understanding Base64's principles and limitations is essential knowledge for any engineer working in web development, API integration, or security research.

Using our online tool, you can immediately Base64 encode and decode any text or file without installing any software.

Try the free tool now

Use Free Tool โ†’