Base64 Encoding Overhead


While Base64 is a popular way to encode raw byte data and send it over a connection that can only handle text, i wonder about its efficiency. Just how much overhead is involved when I convert by bytes to a Base64 encoded string?

In this article I run some tests to see what kind of overhead I can expect when using the Base64 encoder provided in the .NET framework

References

How I tested

To test the practical effects of Base64 encoding I created C# strings of 1, 10, 100, 1000 and 10000 characters in length. I converted each string into a byte array (using System.Text.Encoding.ASCII.GetBytes(SringHere) ) and then encoded the byte array into base64 (using Convert.ToBase64String(ByteArrayHere) ).

 

Results

String Length Byte Array Length Base64 String Length Raw Increase (in Bytes) Overhead
1 1 4 3 300%
10 10 16 6 60%
100 100 136 36 36%
1000 1000 1336 336 33.6%
10000 10000 13336 3336 33.36%

 

From the data I've collected it appears that the overhead associated with using Base64 approaches 33 1/3% the more data you choose to encode.