Base64 Encoder & Decoder

Client-sideNo sign-upFree

Convert text to and from Base64 encoding instantly.

Quick facts

Category
Encoders & Decoders
Best for
Embedding binary data in URLs or JSON payloads
Plain text
Base64
Rm9ybWF0aXEgbWFrZXMgZGV2IHRvb2xzIGZhc3Qu
✓ Done
In-content slot
Was this tool helpful?

Base64 turns arbitrary binary data into plain ASCII text, which is why it shows up everywhere from email attachments to embedded images to API auth headers. Here is exactly how the encoding works and why the output looks the way it does.

On this page

How the encoding works

Base64 re-groups input data from 8-bit bytes into 6-bit chunks, since 6 bits is exactly enough to index into a 64-character alphabet (A-Z, a-z, 0-9, +, /). Three input bytes (24 bits) divide evenly into four 6-bit groups, which is why base64 output is always a multiple of 4 characters, and why encoded data is roughly 4/3 (about 33%) larger than the original.

output_length = ceil(input_bytes / 3) x 4
input_bytes
length of the original data, in bytes
ceil(...)
round up to the next whole number of 3-byte groups
output_length
length of the resulting base64 string, in characters (including padding)

Why the trailing = signs appear

When the input length is not a multiple of 3 bytes, the last group is padded with zero bits to fill out to 6-bit boundaries, and the output is padded with = characters to keep the total length a multiple of 4. One leftover byte produces two = signs; two leftover bytes produce one.

Worked example

Encoding the 3-letter string "Man"

  1. ASCII bytes: M = 77 = 01001101, a = 97 = 01100001, n = 110 = 01101110
  2. Concatenated as 24 bits: 010011 010110 000101 101110
  3. Each 6-bit group is read as a number 0-63 and mapped to the base64 alphabet: 010011 = 19 -> "T", 010110 = 22 -> "W", 000101 = 5 -> "F", 101110 = 46 -> "u"
  4. Result: "TWFu" - exactly 4 characters, no padding needed, because 3 input bytes divide evenly.

Encoding the 2-letter string "Ma" (padding case)

  1. ASCII bytes: M = 77 = 01001101, a = 97 = 01100001 (only 16 bits total, one byte short of a full 3-byte group)
  2. The bits are grouped as 010011 010110 0001(00) - the last group is padded on the right with two zero bits to reach 6 bits
  3. Mapped to the alphabet: 010011 = 19 -> "T", 010110 = 22 -> "W", 000100 = 4 -> "E"
  4. Result: "TWE=" - one padding character, because one byte (8 bits) was short of the next full 3-byte group.

Base64 is not encryption

Base64 is a reversible, publicly known encoding, not a cipher - anyone can decode it instantly with no key. It is used to make binary-safe data survive text-only channels (JSON fields, URLs, email bodies), never to keep data confidential. Don't rely on it to hide sensitive values like passwords or tokens.
VariantWhere it differsTypical use
StandardUses + and / in the alphabetGeneral text/JSON/email use
URL-safeUses - and _ instead of + and /, often omits = paddingEmbedding data directly in a URL or filename
MIMEStandard alphabet, but inserts line breaks every 76 charactersEmail attachment bodies (RFC 2045)

Frequently asked questions

Base64 converts binary or text data into an ASCII string, commonly used to embed images in HTML/CSS, attach files to emails, or pass data safely through URLs and JSON.

Base64 decoding fails when the input contains characters outside the standard Base64 alphabet or has incorrect padding - double check you copied the full encoded string.

Explore more free tools

Formatters, converters, validators, and generators - all free and running entirely in your browser.

Browse more tools