DevBento logoDevBento
Herramientas/Codificador/Decodificador Base64/Base64 Size Overhead: Why Encoded Data Is 33%

Base64 Size Overhead: Why Encoded Data Is 33%

Base64 encoding expands every 3 bytes of binary data into 4 characters. Explains the 33% overhead, padding rules, and practical impact on storage and transfer.

Enviar a:
Herramientas Relacionadas
{}Formateador y Validador de JSON
Formatea, minifica y valida datos JSON al instante. Resaltado de sintaxis, vista de árbol interactiva y detección de errores. Herramienta en tu navegador.
jwtDecodificador JWT
Decodifica e inspecciona JSON Web Tokens en tu navegador. Ve el header, claims del payload y estado de expiración sin enviar nada a ningun servidor.
%20Codificador URL y Convertidor de Entidades HTML
Codifica texto con encodeURIComponent o encodeURI para URL, convierte caracteres especiales HTML a entidades nombradas o numericas. Todo ocurre en tu navegador.
shaGenerador de Hashes
Create a checksum of the decoded output

The Short Answer

Base64 expands every 3 bytes of input into 4 characters, producing exactly 33.33% more data. This ratio is fixed by the encoding math: 3 bytes (24 bits) map to 4 Base64 characters (6 bits each). The overhead is unavoidable without changing the encoding.

For a 1 MB file, Base64 produces approximately 1.33 MB of output. For a 100-byte API token, you get 133 characters.

The Math

Base64 uses a 64-character alphabet, where each character represents 6 bits of data:

Input:  3 bytes = 24 bits
Output: 4 characters × 6 bits = 24 bits

Overhead: (4 - 3) / 3 = 1/3 = 33.33%

The expansion is constant because Base64 cannot represent 8-bit bytes with 6-bit characters without using more characters per chunk. The smallest chunk that works without remainder is 3 input bytes → 4 output characters.

1 byte  input  → 2 characters + 2 padding (=)
                = 4 characters total  (200% overhead)

2 bytes input  → 3 characters + 1 padding (=)
                = 4 characters total  (100% overhead)

3 bytes input  → 4 characters + 0 padding
                = 4 characters total  (33% overhead)

4 bytes input  → 6 characters + 2 padding (=)
                = 8 characters total  (100% overhead)

5 bytes input  → 7 characters + 1 padding (=)
                = 8 characters total  (60% overhead)

6 bytes input  → 8 characters + 0 padding
                = 8 characters total  (33% overhead)

The pattern repeats every 3 bytes. When the input length is a multiple of 3, there is no padding and the overhead is exactly 33%. Otherwise, padding adds 1-2 characters, increasing the overhead slightly.

Practical Size Reference

Input Size Base64 Output Overhead
1 byte 4 bytes 300%
2 bytes 4 bytes 100%
3 bytes 4 bytes 33%
1 KB ~1,365 bytes 33%
10 KB ~13,653 bytes 33%
100 KB ~136,533 bytes 33%
1 MB ~1.33 MB 33%

For anything larger than a few bytes, the overhead converges to 33%.

When the Overhead Matters

Data URIs in CSS/HTML. Embedding a 50 KB image as a Base64 Data URI in your stylesheet adds ~17 KB of encoding overhead. For a single small icon, this is fine. For a page with many images, the overhead compounds and increases HTML/CSS file size, parse time, and memory usage.

/* Small icon: overhead is negligible */
.icon {
  background-image: url("data:image/png;base64,iVBORw0KGgo...");
}

/* Large image: consider a file reference instead */
.hero {
  /* background-image: url("data:image/jpeg;base64,/9j/4AAQ..."); */
  background-image: url("/images/hero.jpg");  /* Better for large files */
}

JWT tokens. A typical JWT header and payload together are 200-500 bytes before encoding. The Base64URL encoding adds ~33%, making the token 270-670 bytes. This is within normal HTTP header limits but worth noting if you are embedding many claims.

Email attachments (MIME). Base64-encoded attachments in emails add 33% to the message size. A 10 MB attachment becomes ~13.3 MB after encoding. Most email systems handle this transparently, but it affects upload time and storage.

Database storage. If you store Base64-encoded binary data in a TEXT column, you are using 33% more storage than a BLOB column would require for the raw bytes. For large binary data, prefer BLOB/BYTEA columns.

When the Overhead Does Not Matter

API tokens and short strings. A 32-byte random token becomes 44 characters in Base64. The extra 12 characters have no measurable impact on network performance or storage.

Configuration files. Storing a small certificate or key as Base64 in a config file adds a few characters. Readability and tooling support outweigh the overhead.

Log files and debugging. Base64 is often used to represent binary data in logs because it is ASCII-safe. The 33% increase is irrelevant for log analysis.

Alternatives When Overhead Is Unacceptable

Base85 (Ascii85). Encodes 4 bytes into 5 characters (25% overhead instead of 33%). Used in PostScript and PDF. The larger character set includes characters that may not be safe in all contexts (URLs, markup), so it is not a drop-in replacement.

Hex encoding. Encodes each byte into 2 hex characters (100% overhead). Worse than Base64 for size, but useful when you need human-readable byte representation (MAC addresses, hash digests).

Binary-safe transport. If your transport layer supports binary data (HTTP with proper Content-Type, WebSocket frames, Protocol Buffers), skip encoding entirely. Base64 exists because many text-based formats cannot carry raw bytes safely.

Compression before encoding. Gzip or Brotli compression before Base64 reduces the input size. The 33% Base64 overhead still applies to the compressed data, but the total output may be smaller than Base64-encoding the uncompressed input.

import base64
import gzip

data = b"A" * 1000  # 1000 bytes, highly compressible

# Base64 without compression: 1332 bytes
encoded_raw = base64.b64encode(data).decode()

# Compress then Base64: ~30 bytes (gzip makes repeated chars tiny)
compressed = gzip.compress(data)
encoded_compressed = base64.b64encode(compressed).decode()
print(f"Raw Base64: {len(encoded_raw)} chars")
print(f"Compressed + Base64: {len(encoded_compressed)} chars")

The Bottom Line

The 33% overhead is intrinsic to Base64. For small data, ignore it. For large binary data, decide whether Base64 is the right tool or whether your transport can handle raw bytes. If you must use Base64 for large data, compress first to reduce the input size before the encoding step.

🔒

Nothing you paste leaves this tab. Every tool runs entirely in your browser — no upload, no server, no account.

© 2026 devbento.dev · construido localmenteChangelog