Bỏ qua đến nội dung chính
FreeOnlineTools Go
Tiếng Việt
how-to

Cách Mã hóa và Giải mã Chuỗi Base64 Từng Bước Một

By FreeOnlineTools Team · Updated 2026-09-02

Quick Answer

Để mã hóa Base64: dán văn bản vào Base64 Encoder và chuỗi mã hóa xuất hiện ngay. Để giải mã Base64: dán chuỗi Base64 vào Base64 Decoder và văn bản gốc xuất hiện. Tất cả xử lý xảy ra cục bộ —dữ liệu không bao giờ được tải lên.

Introduction

Base64 là lược đồ mã hóa binary-to-text chuyển dữ liệu binary thành chuỗi ASCII dùng 64 ký tự in được (A-Z, a-z, 0-9, +, /). Nó được dùng rộng rãi trong tệp đính kèm email, Data URLs, JWT token và API payload. Base64 là mã hóa đảo ngược được, không phải encryption —bất kỳ ai cũng có thể giải mã không cần key.

Step by Step

  1. Open the Base64 tool

    Go to the Base64 Encode & Decode tool page. The tool has two modes: Encode and Decode, selectable via tabs or a toggle.

  2. Enter your input text

    In Encode mode, paste or type the text you want to encode into the input textarea. Any text works — plain strings, JSON, URLs, or even emoji (the tool handles UTF-8 correctly).

  3. Read the Base64 output

    The tool encodes your input instantly using the browser's built-in btoa() function with UTF-8 handling. The Base64 output appears in the result field automatically — no button to click.

  4. Copy the encoded string

    Click the Copy button next to the output field to copy the Base64 string to your clipboard. You can now paste it into your API call, HTML Data URL, or config file.

  5. Decode Base64 back to text

    Switch to Decode mode and paste a Base64 string into the input field. The tool decodes it using atob() with UTF-8 support and shows the original text instantly. If the input is not valid Base64, an error message appears.

Examples

Encode a simple greeting

Input: Hello, World!

Output: SGVsbG8sIFdvcmxkIQ==

Encode JSON data

Input: {"user":"alice","id":42}

Output: eyJ1c2VyIjoiYWxpY2UiLCJpZCI6NDJ9

Decode a Base64 token

Input: SGVsbG8gV29ybGQ=

Output: Hello World

Encode Unicode text with emoji

Input: Hello 🌍

Output: SGVsbG8g8J+MjQ==

Common Problems

  • Non-ASCII characters produce wrong output —use a tool with UTF-8 support like ours; naive btoa() throws on emoji.
  • Base64 output is ~33% larger than the input —every 3 bytes becomes 4 Base64 characters.
  • Padding characters (= or ==) at the end are required —removing them breaks decoding.
  • Base64 is not encryption —anyone can decode it. Never store passwords or secrets as Base64.

Tips

  • Use Base64 for Data URLs to embed small images directly in HTML or CSS without a separate HTTP request.
  • For URL-safe Base64 (used in JWT), replace + with - and / with _, then strip padding.
  • Always validate decoded output before using it in your application —a corrupted Base64 string may decode to garbage.
  • Use our Base64 Encoder and Decoder tools for instant, private processing —no data leaves your browser.

Related Tools

Related Guides

References