What Base64 actually does
Base64 is a binary-to-text encoding. It takes raw bytes — an image, a PDF, a cryptographic key, or just a string of characters — and rewrites them using only 64 safe characters that survive transmission through text-only channels. It is not compression and not encryption; it simply re-expresses the same data in a more portable form.
The reason it exists is historical and practical: many older protocols (email, some HTTP headers, URLs) were designed for plain ASCII text and can corrupt or choke on arbitrary bytes like null characters or control codes. Base64 sidesteps that by mapping everything to letters, digits, and a couple of symbols.
The 64-character alphabet
The standard alphabet (defined in RFC 4648) is:
A–Z→ values 0–25a–z→ values 26–510–9→ values 52–61+→ value 62, and/→ value 63
That is 64 symbols, which is exactly why it is called Base64: each character can represent one of 64 possible values, or 6 bits of information (because 26 = 64).
How 3 bytes become 4 characters
Bytes are 8 bits each; Base64 characters are 6 bits each. The least common multiple of 8 and 6 is 24, so Base64 works in groups of 3 bytes (24 bits), which split evenly into 4 characters (4 × 6 = 24 bits). The process:
- Take 3 bytes and line up their 24 bits.
- Re-slice those 24 bits into four 6-bit chunks.
- Look up each chunk in the 64-character alphabet.
Worked example: encoding "Man"
Take the three ASCII characters M, a, n:
Char: M a n
ASCII: 77 97 110
Bits: 01001101 01100001 01101110
Regroup into 6-bit chunks:
010011 010110 000101 101110
Value: 19 22 5 46
Char: T W F u
Result: "Man" -> "TWFu"
Three bytes in, four characters out. This is also why Base64 makes data roughly 33% larger: every 3 bytes turn into 4 characters of output.
Padding with "="
Real data is not always a multiple of 3 bytes, so Base64 pads the final group. The = sign is a marker that says "these bits were just filler, ignore them":
- 3 bytes → 4 characters, no padding.
Man→TWFu - 2 bytes → 3 characters + one
=.Ma→TWE= - 1 byte → 2 characters + two
==.M→TQ==
So a Base64 string ending in = or == just means the original length was not a clean multiple of 3.
The URL-safe variant
The standard + and / characters cause problems in URLs and filenames — / looks like a path separator and + can be read as a space. The URL-safe alphabet fixes this by substituting:
+→-(hyphen)/→_(underscore)
URL-safe Base64 also commonly omits the padding =, since = is itself awkward in URLs. This variant is what you see in JSON Web Tokens (JWTs) and many web APIs.
Common use cases
- Data URLs: embedding a small image directly in HTML or CSS, e.g.
data:image/png;base64,iVBORw0KG...so no separate request is needed. - Embedding binary in JSON or XML: these formats are text-only, so binary fields (file contents, certificates) are carried as Base64 strings.
- Email (MIME): attachments and non-ASCII message parts are Base64-encoded so 8-bit bytes pass safely through mail servers.
- HTTP Basic authentication: the header sends
Authorization: Basicfollowed by the Base64 ofusername:password.
Important: Base64 is not encryption
This is the single most misunderstood point. Base64 provides no security whatsoever. There is no key and no secret — anyone can decode it instantly with a single function call. HTTP Basic auth, for example, is only as safe as the HTTPS connection carrying it; the credentials themselves are trivially recoverable from the Base64 string. Never use Base64 to "hide" passwords, tokens, or sensitive data. For confidentiality you need real encryption (such as AES or TLS).
Encoding and decoding with Formatly
Formatly's Base64 Encode / Decode tool converts text or data to and from Base64 right in your browser, with proper UTF-8 support so accented letters, emoji, and other multi-byte characters round-trip correctly. Because everything runs locally and nothing is uploaded to any server, you can safely paste tokens, config snippets, or other sensitive strings while you inspect them — the data never leaves your machine.