How to Encode Text to Base64 Online for Free
What It Does
The Base64 encoder takes plain text and converts it into a Base64 encoded string. It transforms each 3 bytes of data into 4 ASCII characters using the Base64 alphabet (A-Z, a-z, 0-9, +, /, and = for padding).
When to Use It
- Embedding images in HTML/CSS as data URLs
- Encoding binary data for JSON or XML transmission
- Creating basic authentication headers for APIs
- Storing binary data in text-based databases
- Encoding email attachments (MIME)
Example
Output: SGVsbG8gV29ybGQ=
Common Errors
- Non-ASCII characters – Base64 works with bytes; ensure proper UTF-8 encoding first
- Very large input – Browser may slow down; consider chunking for huge data
How to Decode a Base64 String Back to Text
What It Does
The Base64 decoder takes a Base64 encoded string and converts it back to its original plain text. It reverses the encoding process by mapping each 4 characters back to 3 bytes of original data.
When to Use It
- Decoding JWT tokens and API authentication headers
- Extracting original data from data URLs
- Reading encoded email attachments
- Processing Base64 data from web APIs
- Debugging encoded database fields
Example
Output: Hello World
Common Errors
- Invalid characters – Base64 strings can only contain A-Z, a-z, 0-9, +, /, =
- Incorrect padding – Missing or extra = at the end
- URL-safe vs standard – Using -_ instead of +/ requires conversion
Common Base64 Decode Errors & Fixes
Error message: "Invalid character", "Non-base64 character", or similar
Cause: The Base64 string contains characters outside the valid alphabet (A-Z, a-z, 0-9, +, /, =). This often happens when copying strings that include newlines, spaces, or URL-safe variants.
Good: SGVsbG8gV29ybGQ=
Error message: "Invalid padding", "Incorrect padding", or "Base64 string length not a multiple of 4"
Cause: Base64 strings must have a length that's a multiple of 4. Padding characters (=) are added to make this happen. Missing or extra padding causes errors.
Fixed: SGVsbG8gV29ybGQ=
Error message: "Corrupted data", "Invalid base64 string", or gibberish output
Cause: The Base64 string has been truncated, modified, or contains characters from a different encoding. Sometimes happens when copying from PDFs or emails.
Error message: "Invalid character" when decoding strings with - or _
Cause: URL-safe Base64 uses - instead of + and _ instead of / to be safe in URLs. Standard Base64 decoders don't recognize these characters.
Convert to standard: SGVsbG8gV29ybGQ/
Add padding: SGVsbG8gV29ybGQ=
Base64 Encoding in Popular Programming Languages
Use these code examples to implement Base64 encoding and decoding in your own applications:
JavaScript (Node.js & Browser)
const text = "Hello World";
const encoded = btoa(text);
const decoded = atob(encoded);
// encoded = "SGVsbG8gV29ybGQ="
// Node.js
const encodedNode = Buffer.from(text).toString('base64');
const decodedNode = Buffer.from(encodedNode, 'base64').toString();
// Handle Unicode properly
function unicodeToBase64(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function(match, p1) { return String.fromCharCode('0x' + p1); }));
}
Python
# Encode string to Base64
text = "Hello World"
text_bytes = text.encode('utf-8')
base64_bytes = base64.b64encode(text_bytes)
base64_string = base64_bytes.decode('utf-8')
# base64_string = "SGVsbG8gV29ybGQ="
# Decode Base64 to string
decoded_bytes = base64.b64decode(base64_string)
decoded_text = decoded_bytes.decode('utf-8')
# decoded_text = "Hello World"
# URL-safe Base64 (for URLs and filenames)
url_safe = base64.urlsafe_b64encode(text_bytes)
Java
public class Base64Example {
public static void main(String[] args) {
String text = "Hello World";
// Encode
String encoded = Base64.getEncoder().encodeToString(text.getBytes());
// encoded = "SGVsbG8gV29ybGQ="
// Decode
byte[] decodedBytes = Base64.getDecoder().decode(encoded);
String decoded = new String(decodedBytes);
// decoded = "Hello World"
// URL-safe version
String urlSafe = Base64.getUrlEncoder().encodeToString(text.getBytes());
}
}
C# (.NET)
using System.Text;
public class Base64Example {
public static void Main() {
string text = "Hello World";
// Encode
byte[] textBytes = Encoding.UTF8.GetBytes(text);
string encoded = Convert.ToBase64String(textBytes);
// encoded = "SGVsbG8gV29ybGQ="
// Decode
byte[] decodedBytes = Convert.FromBase64String(encoded);
string decoded = Encoding.UTF8.GetString(decodedBytes);
// decoded = "Hello World"
}
}
PHP
$text = "Hello World";
// Encode to Base64
$encoded = base64_encode($text);
// $encoded = "SGVsbG8gV29ybGQ="
// Decode from Base64
$decoded = base64_decode($encoded);
// $decoded = "Hello World"
?>
Ruby
text = "Hello World"
# Encode to Base64
encoded = Base64.encode64(text)
# encoded = "SGVsbG8gV29ybGQ=\n" (includes newline)
# Decode from Base64
decoded = Base64.decode64(encoded)
# decoded = "Hello World"
# Strict encoding (no newlines)
strict_encoded = Base64.strict_encode64(text)
Quick Base64 Examples
| Plain Text | Base64 Encoded |
|---|---|
| Hello | SGVsbG8= |
| Hello World | SGVsbG8gV29ybGQ= |
| Base64 Encoding | QmFzZTY0IEVuY29kaW5n |
| 123456789 | MTIzNDU2Nzg5 |
Other Ways People Search for This Tool
This Base64 tool covers all these common search intents:
Encode or decode Base64 strings instantly in your browser — no server, no uploads, completely private.
Frequently Asked Questions
▶ What is Base64 encoding used for?
▶ Is my data safe with this Base64 tool?
▶ How do I decode a Base64 string online?
▶ Why does Base64 end with = or ==?
▶ What's the difference between Base64 and URL-safe Base64?
▶ Can Base64 be decrypted?
▶ Is this Base64 tool completely free to use?
▶ What types of data can I encode with Base64?
▶ Does Base64 encoding increase data size?
▶ Can I use this tool for API testing?