Standard encoding takes three 8-bit bytes (24 bits total) and splits them into four 6-bit chunks, mapping each chunk to the standard Base64 index. If the input text length isn't divisible by three, equals signs (
=) are appended to pad the string. If your encoded outputs are destined for web browser search queries, make sure they are url-safe using our
URL Encoder / Decoder. Here is a simple JavaScript function to encode standard strings:
function encodeStringToBase64(str) {
const bytes = new TextEncoder().encode(str);
const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
return btoa(binString);
}