How To Encode And Decode Base64
📖 Bu rehber ToolPazar ekibi tarafından hazırlanmıştır. Tüm araçlarımız ücretsiz ve reklamsızdır.
What Base64 is — and isn’t
Base64 is the Swiss Army knife of “I need to stuff arbitrary bytes into a text-only channel.” Email attachments, JWT tokens, data URIs in CSS, API auth headers — all lean on it. This guide walks through what Base64 actually does (spoiler: not encryption), when to use it, the variants you’ll run into (standard, URL-safe, MIME), the 33% size overhead, and the common mistakes — using it for security, forgetting to handle padding, and confusing encoding directions.
The encoding mechanics — how 3 → 4
Base64 is a binary-to-text encoding. It represents binary data using 64 ASCII characters (A-Z, a-z, 0-9, +, /) plus = for padding. Every 3 bytes of input become 4 characters of output.
Base64 variants
The entire purpose of Base64 is to let binary data travel through systems that assume text — HTTP headers, JSON values, email bodies, URL parameters, XML.
The 33% size overhead
Input: 3 bytes (24 bits).
When to use Base64
Split those 24 bits into 4 groups of 6 bits each.
When NOT to use Base64
Each 6-bit group maps to one of 64 characters (hence “Base 64”).
Common mistakes
Output: 4 characters, all printable ASCII, safe to transmit anywhere.
Encoding and decoding in different languages
If input isn’t a multiple of 3 bytes, pad with zero bits and indicate with =:
JWT — the example everyone sees
This is why Base64 strings always end with 0, 1, or 2 equals signs. Length is always a multiple of 4.
Run the numbers
Mixing variants is a common bug source: a decoder expecting standard Base64 chokes on URL-safe input containing - or _. Know which variant you’re in.