Base64 Encode/Decode

Encode text to Base64 or decode Base64 strings back to text

Plain text with Unicode characters

Example: Hello, World! 你好世界!...

About Base64

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It is commonly used to encode binary data for transmission over text-based protocols like email or HTTP.

  • Uses 64 characters: A-Z, a-z, 0-9, +, /
  • Padding character: =
  • Output is ~33% larger than input
  • URL-safe variant uses - and _ instead of + and /

Complete Base64 Encode/Decode Guide

Base64 is a widely used binary-to-text encoding scheme that converts binary data into ASCII string format. It plays an important role in web development, data transmission, email attachments, API communication, and more. This tool provides fast, secure Base64 encoding and decoding capabilities, supporting text and Unicode characters, helping developers handle various data encoding needs. Whether embedding images in HTML, transmitting binary data, or processing API responses, Base64 is an indispensable tool.

1
如何使用 / How to Use

Step 1: Select Operation Mode

Click the "Encode" or "Decode" button at the top to select the operation mode. Encode mode converts plain text to Base64 string, decode mode restores Base64 string to original text.

Step 2: Input Data

Paste or type the data to process in the left input box. In encode mode, enter plain text (supports Unicode characters like Chinese), in decode mode, enter Base64 string. You can also click "Upload" to import a file.

Step 3: Execute Conversion

Click the "Encode" or "Decode" button to execute the conversion. The conversion result will immediately appear in the right output box. The tool automatically handles UTF-8 encoding, ensuring correct conversion of special characters like Chinese.

Step 4: View Result Information

After successful conversion, the length and byte size of the result are displayed below the output box. This helps understand the size change of encoded data (Base64 encoding typically increases size by about 33%).

Step 5: Copy or Download Result

Click the "Copy" button to copy the result to clipboard, or click "Download" to save as a text file. Copy function is convenient for quick use, download function is suitable for saving large amounts of data.

Step 6: Quick Mode Switch

Click the swap icon next to the mode selector to quickly switch between encode/decode modes and automatically move the output result to the input box. This is very useful for verifying encoding results.

2
实际应用场景 / Use Cases

1Embedding Images in HTML/CSS

After encoding image files to Base64, they can be directly embedded in HTML or CSS, reducing HTTP requests. This is especially useful for small images like icons and logos. Using Data URL format (data:image/png;base64,...) allows images to load without additional requests.

2API Data Transmission

In RESTful APIs, Base64 is commonly used to transmit binary data (like files, images). After encoding binary data to Base64 string, it can be safely transmitted in JSON, avoiding compatibility issues with binary data in text protocols.

3Email Attachment Encoding

SMTP protocol requires email content to be 7-bit ASCII characters. Base64 encoding converts binary attachments to text format, enabling transmission through email systems. This is a core part of the MIME standard.

4Basic Authentication

HTTP Basic Authentication uses Base64 to encode username and password. Format is "username:password" encoded and placed in Authorization header. While Base64 is not encryption, it can safely transmit credentials when used with HTTPS.

5URL Parameter Passing

When passing data containing special characters in URLs, Base64 encoding can be used first. This avoids the complexity of URL encoding, especially suitable for passing JSON data or binary data.

6Data Storage and Transmission

In some databases or configuration files, Base64 encoding can safely store binary data. It is also commonly used for cross-system data transmission, ensuring data consistency across different platforms and encoding environments.

使用技巧与最佳实践 / Tips & Best Practices

Base64 Is Not Encryption

Base64 is an encoding scheme, not an encryption algorithm. Anyone can easily decode Base64 strings. Do not use Base64 to "hide" sensitive information like passwords or keys. For encryption, use real encryption algorithms like AES.

Watch for Size Increase

Base64 encoding increases data size by about 33%. For large files or frequently transmitted data, this may affect performance. Consider using compression (like gzip) with Base64, or transmit binary data directly.

URL-Safe Variant

Standard Base64 uses + and / characters, which have special meaning in URLs. URL-safe Base64 variant uses - and _ instead, and omits padding character =. Be sure to choose the correct variant when using in URL parameters.

Handle Unicode Characters

When encoding text containing Unicode characters like Chinese, ensure UTF-8 encoding is used. This tool automatically handles UTF-8, but in other environments, pay attention to character encoding settings to avoid garbled text.

Verify Decode Results

After decoding Base64 strings, it is recommended to verify if the result meets expectations. You can use the swap function to re-encode and compare with the original Base64 string to ensure data integrity.

常见问题 / Frequently Asked Questions

技术说明 / Technical Details

Base64 encoding uses 64 printable ASCII characters (A-Z, a-z, 0-9, +, /) to represent binary data. Encoding process: divide every 3 bytes (24 bits) into 4 groups of 6 bits each, then map each group to a character in the Base64 character table. This tool uses browser-native btoa() and atob() functions for encoding and decoding, and handles UTF-8 encoding through TextEncoder/TextDecoder API, ensuring correct handling of Unicode characters. For text containing multi-byte characters like Chinese, it first converts to UTF-8 byte sequence, then performs Base64 encoding. Decoding process is the reverse of encoding: convert Base64 string back to binary data, then parse as text according to character encoding (UTF-8). The tool automatically handles padding characters and validates Base64 string validity. Tech stack: React + TypeScript + Web Crypto API, ensuring high performance and type safety. All operations are completed on the client side, protecting user privacy.

🔒 隐私保护承诺 / Privacy Protection

所有处理都在您的浏览器本地完成,数据不会上传到任何服务器。您的隐私和数据安全是我们的首要任务。
All processing is done locally in your browser. No data is uploaded to any server. Your privacy and data security are our top priorities.