Skip to content
DocsAll
教程

Base64 Encoding Principles: Why Encoded Output Grows by 33%

Timi Tian · Published on July 7, 2026 · Updated on July 12, 2026
Base64EncodingData Encoding

What Is Base64

Base64 is a way to encode binary data into pure text. It uses 64 printable characters (A-Z, a-z, 0-9, +, /) to represent any binary data, allowing binary to pass through text-only channels (such as JSON, XML, URL, email).

Encoding Principle

Character Table

Base64 uses 64 characters: uppercase A-Z (26), lowercase a-z (26), digits 0-9 (10), plus sign +, slash /, totaling 64. The equals sign = is used for end padding.

Encoding Process

  1. Group the input data into 3-byte (24-bit) chunks
  2. Split the 24 bits into 4 groups of 6 bits each
  3. Each 6-bit group maps to one Base64 character (2 to the 6th power = 64, exactly 64 characters)
  4. If fewer than 3 bytes remain, pad with =

Example

3 bytes of input (24 bits) → 4 Base64 characters. So the encoded byte count is 4/3 of the original, i.e., about 133%, an increase of 33%.

Why It Grows by 33%

Fundamentally, 1 byte can represent 256 values (8 bits), while each Base64 character represents only 64 values (6 bits). To represent the same amount of information, 6-bit encoding uses 8/6 = 4/3 as many characters as 8-bit encoding. So Base64-encoded output is 4/3 of the original, an increase of 33%.

This is the inherent cost of Base64—trading space for "text-transmissible."

Encoding Example

The text "Man" (3 bytes ASCII):

  • M = 77 = 01001101
  • a = 97 = 01100001
  • n = 110 = 01101110
  • Combined into 24 bits: 01001101 01100001 01101110
  • Split into 4 groups of 6 bits: 010011 010110 000101 101110
  • Corresponding Base64 characters: T W F u
  • Encoded result: TWFu

3 bytes become 4 bytes, exactly 4/3.

Base64 Variants

Standard Base64

The character table includes + and /, with = padding at the end. Suitable for general use cases.

URL-safe Base64

  • and / have special meanings in URLs, so they are replaced with - and _. Suitable for URL transmission.

Base64URL

The URL-safe variant, commonly used in JWT (JSON Web Token).

Base64 vs Base32 vs Hex

Base64

  • 64-character set
  • Encoded output grows by 33%
  • Characters include uppercase and lowercase letters, digits, and +/, case-sensitive

Base32

  • 32-character set (A-Z, 2-7)
  • Encoded output grows by 60%
  • Case-insensitive, avoids easily confused characters, suitable for manual entry

Hex (Hexadecimal)

  • 16-character set (0-9, a-f)
  • Encoded output grows by 100% (each byte becomes two characters)
  • Simplest and most compatible, but doubles in size

Size: Hex > Base32 > Base64. Choose Base64 for smaller size, Hex for simplicity and compatibility.

Is Base64 Encryption

No. Base64 is encoding, not encryption. Anyone can decode it; there is no key protection. Treating Base64 as encryption is a serious misunderstanding—it merely "disguises" data as gibberish; decoding yields the plaintext.

For sensitive data, use encryption algorithms like AES. Base64 is only for transport encoding.

Use Cases

Data Transmission

Binary data transmitted through text channels (JSON, XML, URL, email) is encoded as text with Base64.

Embedding Small Images

Small images are Base64-encoded and inlined into HTML/CSS to reduce HTTP requests (see Base64 image usage for details).

JWT

JSON Web Token uses Base64URL to encode the header and payload.

Data URI

The data URL protocol uses Base64 to embed resources.

Basic Auth

HTTP Basic Authentication uses Base64 to encode the username and password (note: this is not encryption; pair with HTTPS).

Encode/Decode with DocsAll

Base64 Encode/Decode Tool:

  1. Enter text or a Base64 string
  2. Choose encode or decode
  3. Convert with one click
  4. Copy the result

Processed in the browser; data never leaves your device.

Common Pitfalls

Treating It as Encryption

Base64 is not encryption; don't rely on Base64 alone to "protect" sensitive data.

Encoded Size Increase

Large files encoded with Base64 grow by 33%, increasing transmission and storage costs. Use binary channels when available instead of Base64.

Character Set Confusion

Standard Base64 contains +/; in URLs, these must be escaped or the URL-safe variant used. Mixing variants causes decode failures.

Trailing = Cannot Be Omitted

The padding character = is part of the encoding; omitting it may cause decode errors. Some implementations tolerate omission, but it's non-standard.

Summary

Base64 is encoding, not encryption. It uses 64 characters to represent binary data, and the 33% size increase is an inherent cost. Its purpose is to let binary data pass through text channels. Use the URL-safe variant for URL scenarios. The DocsAll encode/decode tool runs in the browser; data never leaves your device.

T
Timi Tian 创始人 / 全栈工程师

DocsAll 创始人,10 年全栈开发经验,专注浏览器端文档处理技术与隐私保护架构。前新加坡科技公司技术负责人。