What is the real purpose of Base64 encoding?

EncodingBase64

Encoding Problem Overview


Why do we have Base64 encoding? I am a beginner and I really don't understand why would you obfuscate the bytes into something else (unless it is encryption). In one of the books I read Base64 encoding is useful when binary transmission is not possible. Eg. When we post a form it is encoded. But why do we convert bytes into letters? Couldn't we just convert bytes into string format with a space in between? For example, 00000001 00000004? Or simply 0000000100000004 without any space because bytes always come in pair of 8?

Encoding Solutions


Solution 1 - Encoding

Base64 is a way to encode binary data into an ASCII character set known to pretty much every computer system, in order to transmit the data without loss or modification of the contents itself. For example, mail systems cannot deal with binary data because they expect ASCII (textual) data. So if you want to transfer an image or another file, it will get corrupted because of the way it deals with the data.

Note: base64 encoding is NOT a way of encrypting, nor a way of compacting data. In fact a base64 encoded piece of data is 1.333… times bigger than the original datapiece. It is only a way to be sure that no data is lost or modified during the transfer.

Solution 2 - Encoding

Base64 is a mechanism to enable representing and transferring binary data over mediums that allow only printable characters.It is most popular form of the “Base Encoding”, the others known in use being Base16 and Base32.

The need for Base64 arose from the need to attach binary content to emails like images, videos or arbitrary binary content . Since SMTP [RFC 5321] only allowed 7-bit US-ASCII characters within the messages, there was a need to represent these binary octet streams using the seven bit ASCII characters...

Hope this answers the Question

Solution 3 - Encoding

Base64 is a more or less compact way of transmitting (encoding, in fact, but with goal of transmitting) any kind of binary data.

See http://en.wikipedia.org/wiki/Base64

"The general rule is to choose a set of 64 characters that is both part of a subset common to most encodings, and also printable."

That's a very general purpose and the common need is not to waste more space than needed.

Historically, it's based on the fact that there is a common subset of (almost) all encodings used to store chars into bytes and that a lot of the 2^8 possible bytes risk loss or transformations during simple data transfer (for example a copy-paste-emailsend-emailreceive-copy-paste sequence).

(please redirect upvote to Brian's comment, I just make it more complete and hopefully more clear).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJackView Question on Stackoverflow
Solution 1 - EncodinggiorgioView Answer on Stackoverflow
Solution 2 - EncodingAhmed ShahView Answer on Stackoverflow
Solution 3 - EncodingDenys SéguretView Answer on Stackoverflow