What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts arbitrary binary data into a string made up of 64 printable ASCII characters — the uppercase and lowercase Latin alphabet, digits 0–9, and the symbols + and /. Every 3 bytes of input are converted to 4 Base64 characters, so the encoded string is always approximately 33% larger than the original. A padding character (=) is appended when the input length is not a multiple of 3.
Base64 is not encryption — it is a reversible encoding that anyone can decode. Its purpose is to safely transport binary data across channels that only handle text, such as email (MIME), JSON APIs, HTML attributes, and HTTP headers.
How This Encoder/Decoder Works
JavaScript's built-in btoa() and atob() functions only handle Latin-1 (code points 0–255). Passing an emoji or accented character directly throws a InvalidCharacterError. This tool solves that with a two-step approach:
- Encode path:
TextEncoderconverts the input string to a UTF-8Uint8Array, which is then converted to a Latin-1 binary string sobtoa()can safely process it. - Decode path:
atob()produces a binary string, which is converted back to aUint8Arrayand decoded usingTextDecoder, correctly reconstructing any UTF-8 text including emoji.
Standard vs URL-Safe Base64
Standard Base64 uses + and /, which are special characters in URLs. The URL-safe variant (RFC 4648 §5) replaces those with - and _, and strips trailing = padding. This makes the encoded string safe to embed directly in URLs, filenames, and HTTP headers without percent-encoding. Enable the toggle in the tool to switch modes.
Common Use Cases
- Data URLs — embed images directly in HTML/CSS as
data:image/png;base64,… - HTTP Basic Auth — credentials are sent as Base64-encoded
username:password - JWT tokens — the header and payload sections of a JSON Web Token are Base64url-encoded
- Email attachments — MIME uses Base64 to encode binary files for text-based email transport
- API payloads — encode binary blobs (files, icons) to pass them inside JSON strings