Base64 Encoder / Decoder

Encode text to Base64 or decode Base64 back to plain text. Supports standard and URL-safe variants.

The Technical Internals of Base64 Encoding

Base64 is an encoding scheme that maps binary data to 64 printable ASCII characters, standardized by RFC 4648. The core principle involves regrouping every 3 bytes (24 bits) of data into four 6-bit units, each mapped to a character in the Base64 alphabet. The alphabet consists of: uppercase letters A-Z (0–25), lowercase letters a-z (26–51), digits 0-9 (52–61), plus sign + (62), and slash / (63). When the input byte count is not divisible by 3, one or two equals signs = are appended as padding characters. Base64 encoding incurs an expansion rate of approximately 33.3%—meaning the encoded string length is roughly 4/3 times that of the original binary data.

Base64 Variants and Their Use Cases

Standard Base64 (RFC 4648 Section 4):The most widely used version, employed for email attachments (MIME), HTTP Basic Authentication headers, the header and payload portions of JSON Web Tokens (JWT), and values in Kubernetes Secrets. Nearly all programming language standard libraries include built-in Base64 encode/decode support.

Base64URL (RFC 4648 Section 5):Designed specifically for URL and filename safety. Replaces + with - and / with _ in standard Base64, and removes trailing = padding. This allows the encoded result to be directly embedded in URL paths or query parameters without additional percent-encoding. The JWT specification mandates Base64URL encoding.

Scenario: Image embedding in Data URIs.The common data:image/png;base64,iVBORw0KGgo... pattern in web development uses standard Base64 to embed image binary data directly into HTML/CSS, reducing HTTP request counts. Suitable for small icons and placeholders, but not for images exceeding 10KB (due to Base64 expansion and render-blocking).

Frequently Asked Questions

Q: Is Base64 encryption?
A: Absolutely not. Base64 is a reversible encoding, not encryption—it involves no keys whatsoever, and anyone can decode it trivially. Do not use Base64 for security purposes—it is only suitable for data format conversion.

Q: Why does my Base64 string produce garbled text after decoding?
A: You must use the same character encoding for decoding as was used for encoding (typically UTF-8). If the original data was Latin-1 or GBK-encoded text, decoding as UTF-8 will produce garbled output.

Q: What is the difference between Base64 and hexadecimal encoding?
A: Base64 has a 133% expansion rate, expressing 6 bits per character; hexadecimal has a 200% expansion rate, expressing 4 bits per character. Base64 is more compact, while hexadecimal is more readable (exactly two characters per byte).

隐私与安全保证

Your data never leaves your browser. All encoding and decoding operations are performed entirely on the client side. Even text containing API keys, tokens, or sensitive configurations is never transmitted to any remote server.