Base64 Encoder & DecoderSpecialized Version
🔐

Base64 Text Encoder

Encode text to Base64

Base64 Text Encoder

Encode text strings to Base64 for safe transmission through systems that only support ASCII characters. Essential for email, URLs, JSON payloads, and legacy systems. Our encoder processes everything locally in your browser for complete privacy.

Why Encode Text to Base64?

Base64 encoding converts any text—including special characters, Unicode, and emojis—into a safe ASCII string that can pass through any system without corruption or interpretation. Common scenarios include:

  • HTTP Basic Authentication: Sending credentials as Authorization: Basic base64(user:pass)
  • Email Attachments: MIME encoding for email bodies and attachments
  • Data URIs: Embedding text content directly in HTML/CSS
  • JSON Payloads: Including text that might break JSON parsing
  • URL Parameters: Transmitting data through URL query strings
  • Configuration Files: Encoding secrets in environment variables

Text to Base64 Encoding Examples

Original TextBase64 Encoded
Hello WorldSGVsbG8gV29ybGQ=
user:passworddXNlcjpwYXNzd29yZA==
{"key":"value"}eyJrZXkiOiJ2YWx1ZSJ9
你好世界5L2g5aW95LiW55WM
👋🌍8J+Riw==

JavaScript Implementation

``javascript // Browser - Simple ASCII encoding const base64 = btoa('Hello World'); // "SGVsbG8gV29ybGQ="

// Browser - With Unicode/emoji support (recommended) function encodeText(text) { const utf8Bytes = new TextEncoder().encode(text); const binaryString = String.fromCharCode(...utf8Bytes); return btoa(binaryString); }

// URL-safe Base64 (for URLs and filenames) function encodeUrlSafe(text) { const base64 = btoa(encodeURIComponent(text).replace( /%([0-9A-F]{2})/g, (_, p1) => String.fromCharCode(parseInt(p1, 16)) )); return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); }

// Node.js const base64 = Buffer.from('Hello World').toString('base64'); // URL-safe variant const urlSafe = Buffer.from('Hello World').toString('base64url'); `

Decoding Base64 Back to Text

`javascript // Browser (ASCII only) const text = atob('SGVsbG8gV29ybGQ=');

// Browser (with Unicode support) function decodeText(base64) { const binaryString = atob(base64); const bytes = Uint8Array.from(binaryString, c => c.charCodeAt(0)); return new TextDecoder().decode(bytes); }

// Node.js const text = Buffer.from('SGVsbG8gV29ybGQ=', 'base64').toString('utf-8'); `

Common Use Cases

Use CaseCode Example
Basic Auth Header'Basic ' + btoa(user + ':' + pass)
Data URI'data:text/plain;base64,' + btoa(text)
JSON embedding{ "data": btoa(jsonString) }
URL parameter'?data=' + encodeUrlSafe(text)`

Standard vs URL-Safe Base64

FeatureStandardURL-Safe
Character 62+-
Character 63/_
Padding= (required)Often omitted
Use in URLsNeeds encodingSafe as-is
FilenamesProblematicSafe

Size Considerations

Base64 encoding increases size by approximately 33%:

  • 3 bytes of input → 4 characters of output
  • 1 KB text → ~1.33 KB Base64
  • 1 MB text → ~1.33 MB Base64
For large text, consider compressing (gzip) before Base64 encoding to reduce the final size.

Character Set Handling

Content TypeEncoding Approach
ASCII onlySimple btoa() works
Unicode/UTF-8Encode to bytes first
EmojisMust use UTF-8 approach
Mixed contentAlways use UTF-8
Always use UTF-8 encoding for any text that might contain non-ASCII characters to ensure correct round-trip encoding and decoding.

Frequently Asked Questions

Why encode text to Base64?

Base64 encoding converts text to a safe ASCII format that can pass through any system without corruption. It's used for email (MIME), HTTP Basic Authentication, data URIs, embedding text in JSON without escaping, and any scenario where binary-safe transport isn't guaranteed. The tradeoff is ~33% size increase.

Does text encoding preserve unicode and emojis?

Yes, when properly implemented. The text must first be converted to UTF-8 bytes before Base64 encoding. Modern implementations (TextEncoder in browsers, Buffer in Node.js) handle this correctly. The encoded Base64 will be longer for unicode characters (3 bytes per CJK character, 4 bytes per emoji) but will decode back to the exact original text.

How much larger is Base64 encoded text?

Base64 encoding increases size by approximately 33% for ASCII text (3 bytes become 4 characters). For unicode text, the increase depends on the characters: ASCII stays at 33%, but multi-byte UTF-8 characters are already larger before encoding. A 1000-character ASCII string becomes ~1333 characters in Base64. Consider compression before Base64 for very large text.

Related Tools

Explore other tools you might find useful:

Related Calculators