Base64 Encoder

Encode text or files to Base64 format

How to Use Base64 Encoder

  1. 1Paste or type your text into the input area
  2. 2The tool automatically encodes your text to Base64 format
  3. 3Click the copy button to copy the encoded result
  4. 4Use the encoded string in your application or API

Common Use Cases

API Authentication

Encode credentials for HTTP Basic Authentication headers

Data URLs

Create data URLs for embedding small files in HTML/CSS

JSON Transfer

Encode binary data for transmission in JSON APIs

Email Encoding

Encode attachments for MIME email protocols

Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in ASCII string format using 64 printable characters.

Why does Base64 increase file size?

Base64 encoding increases the data size by approximately 33% because it represents 3 bytes of binary data using 4 ASCII characters.

Is Base64 encryption?

No, Base64 is encoding, not encryption. Anyone can decode Base64 data. Never use it to protect sensitive information.

What characters does Base64 use?

Base64 uses A-Z, a-z, 0-9, plus (+), slash (/), and equals (=) for padding, totaling 65 characters.

Best Practices

  • Always validate and sanitize decoded data before use
  • Consider compression before encoding large data
  • Use appropriate MIME types when creating data URLs
  • Remember that Base64 is not suitable for security purposes

Code Examples

// Encode text to Base64
const text = "Hello, World!";
const encoded = btoa(text);
console.log(encoded); // SGVsbG8sIFdvcmxkIQ==

// Encode UTF-8 text (for special characters)
function encodeUTF8(str) {
  return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
    (match, p1) => String.fromCharCode(parseInt(p1, 16))
  ));
}

// Encode file to Base64
function encodeFile(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = () => resolve(reader.result.split(',')[1]);
    reader.onerror = reject;
    reader.readAsDataURL(file);
  });
}