Base64: bytes represented as text
Base64 maps binary bytes to a restricted text alphabet. It is useful when a transport expects text, but provides no encryption or secrecy.
Know your variant
Standard Base64 uses plus and slash; the URL-safe variant replaces them with hyphen and underscore. Padding conventions vary by protocol. Follow the receiving system's requirements.
Text needs an encoding
For Unicode text, first encode the string to UTF-8 bytes, then Base64-encode those bytes. Reverse both steps on decode. Browser btoa() expects byte-valued characters rather than arbitrary Unicode text.
Text → UTF-8 bytes → Base64
Base64 → bytes → UTF-8 textDecoded bytes may be an image, archive or another binary format, rather than valid text. A text-only decoder should report invalid UTF-8 instead of silently replacing bytes.
Reference: MDN: btoa().