From bytes to printable characters
Base64 maps groups of three bytes to four characters using an alphabet of A–Z, a–z, 0–9, +, and /. The final group uses = padding when the input byte length is not divisible by three. Encoded output is roughly one third larger than the original byte sequence.
Hello → SGVsbG8=
Text needs an encoding first
JavaScript strings are not byte arrays. For international text and emoji, first convert the string to UTF-8 bytes with TextEncoder. Then encode those bytes as Base64. Decoding reverses those steps, using TextDecoder to interpret UTF-8.
Encoding is not encryption
No secret is needed to reverse Base64. Encoding a password does not protect it, and an encoded payload can still contain private information. Use an appropriate encryption system when confidentiality is required.
When decoding fails
Check for a different alphabet: Base64URL uses - and _ instead of + and /. Also check padding, truncation, and whether the original bytes are actually text. A Base64 representation of an image is valid binary data, but cannot necessarily be decoded into UTF-8 text.