Text to Base64 Converter
Encode text to Base64 and decode Base64 back to text. UTF-8 and emoji safe, Data URL copy, and code examples in 9 languages. Free, instant, no signup.
Support Our Free Tools
If you find this calculator helpful, please consider supporting our work. Your contribution helps us build and maintain these free tools for everyone.
Buy me a coffeeWhat Is Base64 Encoding?
Base64 is an encoding scheme that converts binary data into a string of 64 ASCII-safe characters — A–Z, a–z, 0–9, + and /. It was invented to solve a fundamental problem: many protocols (email, HTTP headers, XML, JSON) are designed to carry text, but code, images, and binary files are not text. Base64 bridges that gap by representing any binary data as printable characters.
# How it works — 3 bytes → 4 Base64 characters
Input: H e l
Binary: 01001000 01100101 01101100
Groups: 010010 000110 010101 101100
Base64: S G V s
UTF-8 / Emoji Safe
Correctly encodes multi-byte characters — emojis (😊), CJK characters (漢字), Arabic, Hebrew, and all accented letters decode back perfectly.
Copy as Data URL
One click to copy output as a data: URI (data:text/plain;base64,…) ready to embed in HTML, CSS, or SVG without an extra HTTP request.
Bidirectional
Switch between encode and decode modes instantly. Hit Swap to flip the output to the input and continue working in the opposite direction.
When to Use Base64
Data URLs in HTML/CSS
Embed small images, fonts, or SVGs directly in HTML/CSS as data:image/png;base64,… to eliminate HTTP requests. Common in inline email templates.
JWTs & OAuth Tokens
JSON Web Tokens use Base64url (URL-safe Base64) to encode the header and payload. The token is three Base64url sections joined by dots.
Email Attachments (MIME)
The MIME standard (RFC 2045) encodes binary email attachments as Base64 so they survive text-only mail transfer protocols.
API Payloads
Safely transmit binary blobs, certificates, or keys in JSON API payloads. Base64 avoids binary corruption in JSON string values.
HTTP Basic Authentication
HTTP Authorization: Basic headers contain username:password encoded as Base64. Easily decoded — always use HTTPS.
Configuration & Environment
Store binary secrets (private keys, certificates) as Base64 strings in .env files, Kubernetes secrets, and CI/CD environment variables.
Base64 vs Other Encodings
| Encoding | Size Overhead | Charset | Best Used For |
|---|---|---|---|
| Base64 | +33% | A–Z a–z 0–9 + / = | Binary data in text systems: email, APIs, data URIs, JWTs |
| Base64url | +33% | A–Z a–z 0–9 - _ = | Same as Base64 but safe in URLs and filenames (JWTs, OAuth) |
| Hex (Base16) | +100% | 0–9 a–f | Hashes, checksums, memory dumps — human-readable for developers |
| URL Encoding (%) | Varies | Any as %XX pairs | Encoding reserved characters in URLs and query strings |
| Binary (raw) | 0% | All byte values | Direct file storage — no text-safe transport needed |
Base64 Code Examples — 9 Languages
Copy-paste implementations for the most common programming languages. All examples are UTF-8 safe.
// Encode (UTF-8 safe)
const encode = (str) =>
btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
(_, p1) => String.fromCharCode(parseInt(p1, 16))));
// Decode (UTF-8 safe)
const decode = (b64) =>
decodeURIComponent(atob(b64).split('')
.map(c => '%' + c.charCodeAt(0).toString(16).padStart(2,'0')).join(''));
console.log(encode('Hello 👋')); // SGVsbG8g8J+Rsw==
console.log(decode('SGVsbG8g8J+Rsw==')); // Hello 👋import base64
# Encode
text = "Hello 👋"
encoded = base64.b64encode(text.encode('utf-8')).decode('ascii')
print(encoded) # SGVsbG8g8J+Rsw==
# Decode
decoded = base64.b64decode(encoded).decode('utf-8')
print(decoded) # Hello 👋<?php
// Encode
$text = "Hello 👋";
$encoded = base64_encode($text);
echo $encoded; // SGVsbG8g8J+Rsw==
// Decode
$decoded = base64_decode($encoded);
echo $decoded; // Hello 👋using System;
using System.Text;
// Encode
var text = "Hello 👋";
var encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(text));
Console.WriteLine(encoded); // SGVsbG8g8J+Rsw==
// Decode
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(encoded));
Console.WriteLine(decoded); // Hello 👋import java.util.Base64;
import java.nio.charset.StandardCharsets;
// Encode
String text = "Hello 👋";
String encoded = Base64.getEncoder()
.encodeToString(text.getBytes(StandardCharsets.UTF_8));
System.out.println(encoded); // SGVsbG8g8J+Rsw==
// Decode
String decoded = new String(
Base64.getDecoder().decode(encoded), StandardCharsets.UTF_8);
System.out.println(decoded); // Hello 👋import (
"encoding/base64"
"fmt"
)
// Encode
text := "Hello 👋"
encoded := base64.StdEncoding.EncodeToString([]byte(text))
fmt.Println(encoded) // SGVsbG8g8J+Rsw==
// Decode
decoded, _ := base64.StdEncoding.DecodeString(encoded)
fmt.Println(string(decoded)) // Hello 👋require 'base64'
# Encode
text = "Hello 👋"
encoded = Base64.strict_encode64(text)
puts encoded # SGVsbG8g8J+Rsw==
# Decode
decoded = Base64.decode64(encoded)
puts decoded # Hello 👋use base64::{Engine, engine::general_purpose};
// Encode
let text = "Hello 👋";
let encoded = general_purpose::STANDARD.encode(text.as_bytes());
println!("{}", encoded); // SGVsbG8g8J+Rsw==
// Decode
let decoded_bytes = general_purpose::STANDARD.decode(&encoded).unwrap();
let decoded = String::from_utf8(decoded_bytes).unwrap();
println!("{}", decoded); // Hello 👋# Encode
echo -n "Hello 👋" | base64
# Output: SGVsbG8g8J+Rsw==
# Decode
echo "SGVsbG8g8J+Rsw==" | base64 --decode
# Output: Hello 👋
# File encode
base64 -i image.png -o image.b64
# File decode
base64 -d image.b64 -o image.pngFrequently Asked Questions
- What is Base64 encoding?
- Base64 is an encoding scheme that converts binary data into a string of 64 ASCII characters (A–Z, a–z, 0–9, +, /). It was designed to safely transmit binary data over channels built for text — such as email (MIME), HTTP headers, and JSON APIs.
- Is Base64 a form of encryption?
- No. Base64 is encoding, not encryption. Anyone can decode a Base64 string without a key. It provides no confidentiality or security — it only changes the format of the data. For security, use AES, RSA, or another encryption algorithm.
- Does Base64 increase data size?
- Yes — by approximately 33%. Base64 encodes every 3 bytes (24 bits) of binary data as 4 ASCII characters (32 bits). So a 3 KB file becomes roughly 4 KB when Base64 encoded. This overhead is the trade-off for text-safe transport.
- What is URL-safe Base64?
- Standard Base64 uses + and / which have special meaning in URLs. URL-safe Base64 (Base64url) replaces + with - and / with _ so the string can be used in URLs and filenames without percent-encoding. Common in JWTs and OAuth tokens.
- What is a Base64 Data URL?
- A Data URL embeds file content directly in an HTML or CSS file using Base64: data:[mediatype];base64,[encoded data]. Example: <img src="data:image/png;base64,iVBORw0K...">. This eliminates an HTTP request for small images.
- How does this tool handle emojis and special characters?
- The tool uses a UTF-8-safe encoding method. Before encoding, multi-byte characters (emojis, accented letters, CJK characters) are properly encoded to their UTF-8 byte sequences so the Base64 output accurately represents the original text and decodes back perfectly.
- What is the Base64 alphabet?
- The 64 characters are: A–Z (26), a–z (26), 0–9 (10), + (1), / (1) = 64. The = character is used as padding at the end if the input length is not a multiple of 3 bytes.
- When should I use Base64 vs hex encoding?
- Use Base64 when you need compact text-safe binary representation (images in HTML, API payloads, JWTs). Use hex when human readability for developers matters more than size (debugging binary data, hash values, memory dumps). Base64 is ~33% larger than binary; hex is ~100% larger.
- Can I encode JSON with Base64?
- Yes. Encoding a JSON string to Base64 is common in APIs for safely passing structured data in headers, query parameters, or systems that don't support raw JSON. Decode the Base64 string first, then parse the JSON.
- What does the = padding at the end mean?
- Base64 works in groups of 3 bytes. If the input length is not a multiple of 3, = padding characters are added to make the output a multiple of 4 characters. One = means 1 padding byte was needed; == means 2.
Explore All Tools
82 free tools — no signup required
All 82 tools are free · No signup · No ads
