Skip to main content

Try it Live

Run Base64 examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Base64 API.
Base64 is a binary-to-text encoding scheme that converts binary data into ASCII text. This guide teaches Base64 fundamentals using Tevm.

What is Base64?

Base64 encoding converts binary data (bytes) into printable ASCII characters using an alphabet of 64 characters. It enables transmission of binary data through text-only channels. Character set: A-Z, a-z, 0-9, +, / (standard) or -, _ (URL-safe)

Why Base64?

Binary data cannot be safely transmitted through systems that expect text:
  • Email protocols (MIME) - Expect ASCII text
  • JSON/XML - Cannot embed raw binary data
  • URLs - Require safe character sets
  • Data URIs - Embed images/files in HTML/CSS
Base64 solves this by encoding binary into a restricted character set guaranteed to survive text processing.

Encoding Algorithm

Base64 groups bytes into 24-bit chunks (3 bytes) and splits them into four 6-bit values. Each 6-bit value (0-63) maps to a character.

Step-by-step

Padding

When input length isn’t divisible by 3, Base64 adds padding:
  • 1 byte remaining: Encode as 2 characters + == padding
  • 2 bytes remaining: Encode as 3 characters + = padding
  • 3 bytes (no remainder): No padding

Size Overhead

Base64 increases data size by ~33%:

Complete Examples

Encode Bytes to Base64

Encode Hex to Base64

Decode Base64 to Bytes

Round-trip: Bytes → Base64 → Bytes

Standard vs URL-Safe

Standard Base64

Uses + and / characters, includes = padding:

URL-Safe Base64

Uses - and _ instead of + and /, omits padding:

Common Use Cases

JSON-RPC Binary Data

Ethereum JSON-RPC often requires Base64 for binary data:

Data URIs

Embed binary data in HTML/CSS/JSON:

Wallet Keystore Files

Ethereum keystore files use Base64 for encrypted keys:

JWT Tokens

JSON Web Tokens use URL-safe Base64:

Validation

Always validate Base64 before decoding:

Resources

Next Steps