# Base64 Encoder & Decoder

- **URL:** https://codeasystem.com/calculators/developer/base64-encoder-decoder/
- **Category:** developer
- **Description:** Convert text to Base64 and back with full UTF-8 support; multilingual characters and emoji survive every round trip.
- **Primary output:** Base64 encoded: SGVsbG8sIOS4lueVjCE=

## Inputs
- Text / Base64 (name: `text`, type: textarea, example: Hello, world! or SGVsbG8sIHdvcmxkIQ==)
- Direction (name: `direction`, type: select)

## Outputs
- Base64 encoded: SGVsbG8sIOS4lueVjCE=
- Input length: 14 UTF-8 bytes
- Encoded length: 20 characters
- Encoding scheme: standard Base64 (RFC 4648) with padding

## Formula / methodology
```
Base64: groups of 3 bytes → 4 characters; padding = pads the final partial group
```

Text is first converted to UTF-8 bytes, then each group of three bytes (24 bits) is split into four six-bit values mapped onto the standard A–Z, a–z, 0–9, +, / alphabet. A leftover group of one or two bytes is padded with one or two “=” signs.

Decoding reverses the mapping after validating the alphabet, length multiple of four and correct padding placement, so corrupt input fails loudly instead of silently producing garbage bytes.

## Assumptions & limitations
- Standard alphabet with + and / (not the URL-safe -_ variant).
- Whitespace inside Base64 is ignored when decoding.
- Decoded bytes are interpreted strictly as UTF-8.

## How to use
1. **Paste your content**; Any text in any language; encoding handles the full Unicode range.
2. **Pick the direction**; Encode turns text into Base64; decode expects valid Base64 and returns text.
3. **Copy the result**; Encoded output includes standard “=” padding accepted everywhere.

## Example
“Hello, 世界!” contains multibyte UTF-8 characters; its encoding is the classic SGVsbG8sIOS4lueVjCE=; proof the pipeline is Unicode-safe.

Result for these inputs:

```
Base64 encoded: SGVsbG8sIOS4lueVjCE=
```

## About this calculator
### What Base64 is actually for

Base64 converts arbitrary bytes into printable ASCII safe for channels designed around text: email attachments, JSON string fields, data URIs, HTTP basic auth headers. It costs about 33% extra size; it is an encoding, never encryption.

### The Unicode trap

Naïve btoa() usage throws on characters above U+007F because it treats each char as a byte. Correct handling encodes UTF-8 bytes first; which is exactly what this tool does, so 世界 and emoji survive intact both directions.

### Padding rules worth knowing

- Length divisible by 3 → no padding
- One byte left over → “==”
- Two bytes left over → “=”
- Stray “=” anywhere else means corruption

## FAQs
### Is Base64 encryption?

No; it is a reversible encoding with no key. Anyone can decode it instantly; use it for transport compatibility, never secrecy.

### Why does encoded output end with = sometimes?

Padding completes the final incomplete 3-byte group so total output length is always a multiple of four characters.

### Can I decode URL-safe Base64 (- and _)?

Not directly here; replace dashes with + and underscores with / first, then add missing padding.

### Why did decoding fail?

Most often a stray character outside the alphabet, wrong padding, or a length that is not a multiple of four. The error names the specific problem.

## Related calculators
- [URL Encoder & Decoder](https://codeasystem.com/calculators/developer/url-encoder-decoder/)
- [HTML Entity Escaper & Unescaper](https://codeasystem.com/calculators/developer/html-entity-escaper/)
- [SHA Hash Generator](https://codeasystem.com/calculators/developer/hash-generator/)

---
Last updated: 2026-08-23 · Version: 1.0.0 · [HTML version](https://codeasystem.com/calculators/developer/base64-encoder-decoder/)
