Plain text
Base64

How to encode text to Base64

  1. Paste any text into the input field — plain text, JSON, XML, credentials, or any Unicode content including emoji.
  2. Click "Convert" — the Base64-encoded string appears instantly in the output panel.
  3. Switch to "Decode" using the toggle above if you need to decode Base64 back to text.
  4. Click "Copy" to copy the encoded string, or "Download .txt" to save the file.
  5. Use the output in a URL, HTTP header, data URI, JWT token, or any context that requires ASCII-safe encoding.

How Base64 encoding works

Base64 encoding converts arbitrary binary data into a string of 64 printable ASCII characters. The encoder reads input 3 bytes at a time, splits each group into four 6-bit values, and maps each value to a character from the Base64 alphabet (A–Z, a–z, 0–9, +, /). If the input length is not divisible by 3, one or two = padding characters are appended to make the output length a multiple of 4.

This converter uses the browser's TextEncoder API to handle full Unicode input — including emoji, CJK characters, Arabic, and Cyrillic — by encoding the text to UTF-8 bytes first, then encoding those bytes to Base64. This is the correct approach for multilingual text; using btoa() directly on Unicode strings throws an error for any character with a code point above 127.

How the converter encodes Unicode text to Base64
// The converter uses TextEncoder for proper Unicode support:
function base64Encode(text) {
  const bytes  = new TextEncoder().encode(text)
  const binary = Array.from(bytes, b => String.fromCharCode(b)).join('')
  return btoa(binary)  // standard Base64
}

base64Encode('Hello, World!')  // → 'SGVsbG8sIFdvcmxkIQ=='
base64Encode('Привіт, світ!') // → correctly encoded (TextEncoder handles UTF-8)
base64Encode('Hello 🌍')       // → 'SGVsbG8g8J+MjQ=='

// btoa() alone throws for non-ASCII input:
btoa('Привіт')  // ❌ InvalidCharacterError

Who uses Base64 encoding

Base64 is used whenever binary or arbitrary text data needs to be transmitted or stored in a context that only supports ASCII-safe characters — URLs, HTTP headers, email bodies, HTML attributes, and configuration files.

  • API authentication — HTTP Basic Auth encodes credentials as Base64: Authorization: Basic base64(username:password). Every API using Basic Auth generates and decodes these strings.
  • JWT tokens — the header and payload sections of a JSON Web Token are Base64URL-encoded. Inspecting the claims inside a JWT requires decoding these sections.
  • Data URIs — embedding images, fonts, or SVGs directly in HTML or CSS as data:image/png;base64,... avoids additional HTTP requests.
  • Environment variables — storing binary config (TLS certificates, private keys) in environment variables that only accept text strings.
  • Email attachments — MIME encoding uses Base64 to transmit binary file attachments through email protocols that only support 7-bit ASCII.
  • Webhook payloads — some platforms encode event data in Base64 before including it in a JSON payload to ensure safe transmission.

Base64 alphabet, output size, and variants

The standard Base64 alphabet uses 65 characters: 64 data characters plus = for padding. Base64URL (used in JWTs and URL parameters) replaces + with - and / with _ to avoid conflicts with URL-reserved characters.

Value rangeCharactersCount
0–25A–Z26
26–51a–z26
52–610–910
62+ (or - in Base64URL)1
63/ (or _ in Base64URL)1
pad= (padding)1 or 2

Output size: every 3 bytes of input produce 4 Base64 characters. The encoded output is always 4/3 × the input byte length, rounded up to the nearest multiple of 4. "Hello" (5 bytes) encodes to "SGVsbG8=" (8 characters — a 60% size increase). Base64 encoding always makes data larger, never smaller.

When to use Base64 — and when not to

Use Base64 encoding when:

  • The transport channel is ASCII-only — email (SMTP), HTTP headers, URL query parameters, and some older protocols only support 7-bit ASCII characters.
  • Embedding binary data in text formats — including images or fonts in CSS/HTML as data URIs, or embedding file contents in JSON or XML payloads.
  • Storing binary data in text fields — database columns, environment variables, or config files that cannot hold raw binary bytes.
  • Protocol requirements specify it — HTTP Basic Auth, JWT, and MIME email attachments all require Base64 encoding by specification.

Do NOT use Base64 when:

  • You think it provides security — Base64 is not encryption. Anyone can decode it instantly. Sensitive data encoded in Base64 is just as exposed as plain text.
  • You want to compress data — Base64 expands output by ~33%. Use gzip or Brotli if you want smaller output.
  • The transport already handles binary — modern HTTP APIs, WebSockets, and multipart form uploads do not require Base64 for binary payloads.
  • You're hiding passwords or tokens — encoding a secret in Base64 and committing it to source code is not more secure than plain text. Use a secrets manager.

Common Base64 patterns you'll encounter

Once you recognize the Base64 pattern — blocks of letters, digits, + and /, ending with 0–2 = signs — you'll start noticing it in many places. The examples below show where Base64 appears in everyday web development.

Base64 in HTTP Basic Auth, JWT, and data URIs
// HTTP Basic Auth header (username:password encoded):
Authorization: Basic dXNlcjpwYXNzd29yZA==
// Decoded: user:password

// JWT token (three Base64URL sections separated by dots):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9   ← header (Base64URL)
.eyJzdWIiOiIxMjM0IiwibmFtZSI6IkFsaWNlIn0  ← payload (Base64URL)
.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c  ← signature (binary)

// CSS data URI (SVG image embedded directly):
background-image: url(data:image/svg+xml;base64,PHN2Zy4uLj4=)

// HTML img tag with Base64 encoded image:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." />

Frequently Asked Questions

What is Base64 encoding used for?
Base64 encoding converts binary data (including text) into a string of printable ASCII characters. It is used when data needs to be transmitted through channels that only support ASCII — HTTP Basic Auth headers, JWT tokens, data URIs in HTML/CSS, MIME email attachments, and environment variables storing binary secrets.
Is Base64 a form of encryption?
No. Base64 is encoding, not encryption. It is a reversible transformation with no key — anyone can decode a Base64 string instantly. Do not use Base64 to protect sensitive data. Use proper encryption (AES, RSA) or a secrets management system for anything that needs to remain confidential.
Does Base64 encoding compress data?
No — it makes data larger. Every 3 bytes of input produce 4 Base64 characters, so the output is approximately 33% larger than the input. If you want to reduce size, use a compression algorithm like gzip or Brotli before or instead of Base64.
Why does the output sometimes end with = or ==?
Base64 encodes data in groups of 3 bytes. If the input length is not a multiple of 3, padding characters (=) are added to make the output length a multiple of 4. One = means the input had a remainder of 2 bytes; == means a remainder of 1 byte. This is standard and expected.
What is the difference between standard Base64 and Base64URL?
Standard Base64 uses + and / as the 62nd and 63rd characters. Base64URL replaces + with - and / with _ to produce URL-safe strings that do not need percent-encoding in URLs. Base64URL is used in JWT tokens, URL query parameters, and file names. The = padding may also be omitted in Base64URL.
Does the converter support Unicode and emoji?
Yes. The converter uses the browser's TextEncoder API to convert input to UTF-8 bytes before encoding. This correctly handles all Unicode — accented letters, CJK characters, Arabic, Cyrillic, and emoji. Using btoa() directly on non-ASCII text throws an InvalidCharacterError; the TextEncoder approach avoids this.
How do I decode a Base64 string I received?
Switch to "Decode" using the toggle above the tool, paste the Base64 string, and click Convert. The decoded plain text appears instantly. This is useful for inspecting JWT payload claims, HTTP Basic Auth credentials, or any Base64-encoded data you receive.
Can I encode binary files (images, PDFs) with this tool?
This converter is designed for text input — it treats the input as a UTF-8 string. For encoding binary files as Base64 data URIs, use a file encoder that reads raw bytes directly. This tool correctly encodes any Unicode text, including JSON, XML, HTML, and code snippets.
What is a data URI and how does Base64 relate to it?
A data URI embeds file content directly in a URL: data:[mediatype];base64,[encoded content]. For example, data:image/png;base64,iVBORw0K... embeds a PNG image inline in HTML or CSS. The file bytes are Base64-encoded to produce the ASCII-safe string after the comma.
How large is the Base64 output compared to the input?
The output is approximately 33% larger than the input. Every 3 input bytes produce 4 Base64 characters. A 3 KB text file becomes a ~4 KB Base64 string. This overhead is the standard trade-off for ASCII-safe encoding.
Is any data sent to a server during encoding?
No. The entire encoding runs in your browser using the built-in TextEncoder and btoa() APIs. No data is transmitted over the network — there are no privacy concerns, no file size limits, and no rate limits.
What characters appear in a valid Base64 string?
Standard Base64 uses only A–Z, a–z, 0–9, +, /, and = (padding). If you see - and _ instead of + and /, the string is Base64URL-encoded (used in JWTs and URL parameters). If you see other characters, the string may be corrupted or URL-encoded.