Base64 Encoding Explained: How It Works and When to Use It

A practical guide to Base64: the 64-character alphabet, padding, URL-safe variants, size overhead and common developer use cases.

What Base64 actually does

Base64 maps every 3 bytes (24 bits) into 4 printable characters chosen from a 64-symbol alphabet (A–Z, a–z, 0–9, + and /). It is an encoding, not encryption: it makes binary data safe for text-only channels such as JSON payloads, email bodies, HTML attributes and URLs. Anyone can decode it, so never treat Base64 as protection.

Padding and alphabets

When input length is not a multiple of 3, = padding characters are added. For URLs and filenames, RFC 4648 defines the URL-safe alphabet that replaces + and / with - and _. Many systems strip padding too — our Base64 tools handle standard, URL-safe and unpadded variants.

Size overhead

Encoded output is about 33% larger than the input. That overhead is the price of transporting arbitrary bytes through a text channel. For large payloads, compress first (gzip) and then encode.

相關工具