What is Base64 Encoding?

Base64 encoding is everywhere in web development. This guide explains how it works and when to use it effectively.

Why Base64 Exists

Many systems only handle text safely. Binary data can contain characters that break these systems. Base64 converts binary to safe text using only 64 characters guaranteed to survive transmission. The 64 characters are A-Z, a-z, 0-9, +, and /. The = character is for padding. This safety comes at a 33% size increase cost. When you see a long string of letters and numbers ending with = signs, you're probably looking at Base64.

The 64 Characters

Standard Base64: A-Z (26), a-z (26), 0-9 (10), + and / (2), with = for padding. Base64URL replaces + with - and / with _ for URL safety. You'll see Base64URL in JWTs and URL parameters. The = padding appears when input length isn't a multiple of 3 bytes. Some systems allow omitting padding.

How It Works

Base64 splits binary into 6-bit groups, each mapping to one of 64 characters. Three bytes become four characters. Example: "Hi" (72, 105) → combine bits → split into 6-bit groups → map to characters → add padding → "SGk=" The encoding is deterministic and lossless. Same input always produces same output, and you can always recover the original.

Prova verktyget

Base64 Kodare/Avkodare

Base64 Kodare/Avkodare

Relaterade artiklar