Base64 Encoder and Decoder

Decode
Encode
const message = "Hello World";

const encoded = btoa(message);
const decoded = atob(encoded);

console.log(`Base64 encoding of ${message}: ${encoded}`);
console.log(`Base64 decoding of ${encoded}: ${decoded}`);

The Base64 encoding

Like Base32, Base64 is anencoding designed to represent arbitrary binary data in a consitently text-based format. This is useful when tramsitting data in ways that may require a text-based representation. A common use case of Base64 is the encoding of binary assets like images or executables in text files.

Base64 uses an alphabet with 64 possible values, encoding 6-bit (26) values. This means that Base64 will encode 4 values for each group of 3 bytes. The most common Base64 alphabet, defined by RFC 4648 §4, is shown below. Other common variants include Base64url, the MIME transfer encoding, and the obsolete Base64 for Privacy-Enhanced Mail.

Base64 alphabet defined by RFC 4648 §4
ValueMarkValueMarkValueMarkValueMark
0A16Q32g48w
1B17R33h49x
2C18S34i50y
3D19T35j50y
4E20U36k51z
5F21V37l520
6G22W38m542
7H23X39n553
8I24Y40o564
9J25Z41p575
10K26a42q586
11L27b43r597
12M28c44s608
13N29d45t619
14O30e46u62+
15P31f47v63/
padding=