tags:

views:

314

answers:

5

I would like to understand it better.

Do I really need it? Can't I simple use pure string?

I heard it expand the size of things encoded by 30% (at least for images).

+13  A: 

The primary use case of base64 encoding is when you want to store or transfer data with a restricted set of characters; i.e. when you can't pass an arbitrary value in each byte.

Mehrdad Afshari
And also, if You want to send binary data over string protocols (like JSON) where bianry could break Your string due to unwanted chars like quotes 0x00, etc...
Rafal Ziolkowski
Rafal: That's basically an instance of a "restricted character set".
Mehrdad Afshari
I wish I could approve your answer too. Great answer.
Ismael
+12  A: 

Originally some protocols only allowed 7 bit, and sometimes only 6 bit, data.

Base64 allows one to encode 8 bit data into 6 bits for transmission on those types of links.

Email is an example of this.

Adam Davis
Mostly 7 bit because the 8th bit was used for parity on many serial transmission protocols.
Paul Tomblin
Great detail i never thought. I feel updated.
Ismael
A: 

Whether or not to use it depends on what you're using it for.

I've used it mostly for encoding binary data to pass through a mechanism that has really been created for text files. For example - when passing a digital certificate request around or retrieving the finished digital certificate -- in those cases, it's often very convenient to pass the binary data as Base 64 via a text field on a web form.

I probably wouldn't use it if you have something that is already text and you just want to pass it somewhere.

bethlakshmi
+2  A: 

One application is to transfer binary data in contexts where only characters are allowed. E.g. in XML documents/transfers. XML-RPC is an example of this.

Peter Mortensen
A: 

I use it for passing around files that tend to get chewed up by email programs because they look like text files (e.g. HL7 transcripts for replay).

Joshua