Base64 works on bytes, not characters:
- Encode: your text is first converted to UTF-8 bytes with
TextEncoder(this is what keeps non-English text intact), then every 3 bytes are regrouped into 4 six-bit values, each mapped to a character inA–Z a–z 0–9 + /. If the byte count isn't a multiple of 3,=padding is added. - Decode: the process reverses — the 64-character alphabet maps back to bytes, padding is stripped, and
TextDecoderrebuilds the original UTF-8 text.
A common bug in naive tools is calling btoa() directly on Unicode text, which corrupts anything outside Latin-1. This tool encodes UTF-8 bytes first, so it doesn't.