DevToolsForYou

Base64 Encoding Cheatsheet

A quick reference for Base64 encoding rules, alphabet, variants (standard vs URL-safe), padding, and common use cases.

Updated Apr 11, 2026
Try the Base64 Encoder / Decoder

Sections

  1. The Base64 Alphabet
  2. Encoding Rules
  3. Standard vs URL-Safe
  4. Common Use Cases
  5. Quick Examples

The Base64 Alphabet

Base64 encodes every 3 bytes of input into 4 printable ASCII characters drawn from a 64-character alphabet.

IndexCharIndexChar
0–25A–Z26–51a–z
52–610–962+ (standard) or - (URL-safe)
63/ (standard) or _ (URL-safe)pad= (padding character)

Encoding Rules

RuleDetail
Group into 3-byte chunksTake 3 bytes (24 bits) of input at a time
Split into four 6-bit groupsEach 6-bit group indexes into the 64-char alphabet
Padding with =If input length is not divisible by 3, pad output with = to make it divisible by 4
1 remaining byteProduces 2 Base64 chars + == padding
2 remaining bytesProduces 3 Base64 chars + = padding
Output size⌈n / 3⌉ × 4 characters — always a multiple of 4

Standard vs URL-Safe

VariantChar 62Char 63PaddingUse Case
Standard (RFC 4648 §4)+/= required — MIME, PEM, general encoding
URL-safe (RFC 4648 §5)-_= often omitted — JWTs, URL query params, filenames

Common Use Cases

Use CaseNotes
Data URIsdata:image/png;base64,<encoded> — embed images in HTML/CSS
JWTsHeader and payload are Base64URL-encoded (no padding)
HTTP Basic AuthAuthorization: Basic base64(username:password)
Email attachmentsMIME uses standard Base64 with 76-char line wrapping
Binary in JSONEncode binary blobs before placing in JSON strings
Secrets in env varsBase64 makes binary keys safe to store as strings

Quick Examples

Input (ASCII)Base64 Output
MTQ==
MaTWE=
ManTWFu
helloaGVsbG8=
hello worldaGVsbG8gd29ybGQ=
{"alg":"HS256"}eyJhbGciOiJIUzI1NiJ9
Related guidesAll guides →