Binary Data – any data represented in binary form. It is a sequence of bytes. Each byte is 8 bits.
The term “binary file” is often used as a term meaning “non-text file”.
Binary files typically contain bytes that are intended to be interpreted as something other than text characters.
* Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.
* Base64 is a way to encode binary data into a character set known to pretty much every computer system, in order to transmit the data without loss or modification of the contents itself.
When you have some binary data that you want to ship across a network, you generally don’t do it by just streaming the bits and bytes over the wire in a raw format.
Why?
…because some media are made for streaming text. You never know — some protocols may interpret your binary data as control characters (like a modem), or your binary data could be screwed up because the underlying protocol might think that you’ve entered a special character combination (like how FTP translates line endings).
So to get around this, people encode the binary data into characters. Base64 is one of these types of encodings. Why 64? Because you can generally rely on the same 64 characters being present in many character sets, and you can be reasonably confident that your data’s going to end up on the other side of the wire uncorrupted.
* Some transportation protocols only allow alphanumerical characters to be transmitted. Just imagine a situation where control characters are used to trigger special actions and/or that only supports a limited bit width per character. Base64 transforms any input into an encoding that only uses alphanumeric characters, +, / and the = as a padding character.
Text content
M a n
ASCII
‘M’ 77 (0x4d) ‘a’ 97 (0x61) ‘n’ 110 (0x6e)
Bit pattern
‘M’, 77 = 64 + 0 + 0 + 8 + 4 + 0 + 1
01001101
‘a’, 97 = 64 + 32 + 0 + 0 + 0 + 0 + 1
01100001
‘n’ 110 = 64 + 32 + 0 + 8 + 4 + 2 + 0
01101110
Base 64 means that groups of 6 bits (6 bits have a maximum of 2^6 = 64 different binary values) are converted into individual numbers from left to right (in this case, there are four numbers in a 24-bit string), which are then converted into their corresponding Base64 character values:
01001101 01100001 01101110
becomes
010011 010110 000101 101110
where
010011 is 19
010110 is 22
000101 is 5
101110 is 46
The base 64’s table (as opposed to ASCII table),
converts 0-25 as ‘A’ – ‘Z’,
26-51 as ‘a’ – ‘z’,
and 52-61 as 0 – 9
Hence
Base64-encoded
010011 (19) is T
010110 (22) is W
000101 (5) is F
101110 (46) is u