Webdevtoolsonline.com Home About Contact
Google

Base64 encode / decode an encoded / un-encoded string

Enter the data to be processed:


 

 

The result will apear here:

Base64 encoding explained

About the algorithm

The base64 algorithm was originally developed for use with MIME encoded messages such as e-mails. Thanks to the fact that a base64 encoded value will only consist of 65 characters ("A-Z", "a-z" "/" "+" and "=") it can be used to convert binary files into a simple ASCII string that can be embedded it all kinds of text-based data tranfer methods of which e-mail messages are a great example.

How base64 works

The algorithm basicly takes seriez of 8 bit blocks and spreads the bits out into a series of 6 bit blocks. The highest number 6 bits can contain is 64, hence it's name base64. For example, take the following series of bytes "10101010 10101010 10101010". Each byte consists of 8 bits. Like I said Base64 will regroup these bytes from groups of 8 to groups of 6, which results in "101010 101010 101010 101010".
The first characters of the ASCII standard contain a lot of so called "control characters" such as newline, bell, carrier return and so on. Typically characters you'd rather not have in an encoded string. That's why these characters are mapped to a set of normal characters being: "A-Z", "a-z", "/" and "+".

...but what if....

As our example is inputting 3 groups of 8 and outputting 4 groups of 6, what would happen when the input is not an even multiple of 3? We could not encode it properly!

The solution is pretty simple. We need to somehow mark the end of the output to show that the input was less then an even multiple of 3. It was decided to use an "=" character as the 65th character which signifies an empty byte. As all ASCII characters consist of 7 bits, the 65th character is not out-or-range.

 

 

This website is hosted by Vendite.nl