Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store sql Base-64 vs. binary disk space

Tags:

c#

sql-server

Which way is the most efficient way to save sql data compare base-64 or binary? I am using a SQL Server database.

I believe with binary we have to store it as binary or text data but with base-64 we can store it as text.

I think binary is base on 8 bits/1 byte and base 64 is what I don't know

The example of the text HELLO WORLD. TODAY IS MONDAY.
[Base 64 result][2]:SEVMTE8gV09STEQuIFRPREFZIElTIE1PTkRBWS4=
[Binary Result][3]:01001000 01000101 01001100 01001100 01001111 00100000 01010111 01001111 01010010 01001100 01000100 00101110 00100000 01010100 01001111 01000100 01000001 01011001 00100000 01001001 01010011 00100000 01001101 01001111 01001110 01000100 01000001 01011001 00101110 
like image 296
John Lovus Avatar asked May 16 '26 23:05

John Lovus


2 Answers

Base 64 only uses 6 bits per character, the other 2 bits of the byte are wasted, meaning you are 33.3% less efficient than using BLOB storage.

The advantage of Base64 is for when you MUST use a safely transferable text string, and the loss in storage efficiency is acceptable, such as in an XML file.

like image 127
Neil N Avatar answered May 19 '26 12:05

Neil N


The answer depends on your definition of "efficient". I assume you mean this in terms of storage space used. Base64 encoding uses 64 printable characters (6 bits) to represent all 256 byte combinations (8 bits), e.g. your net storage utilization is only 75%. Binary format uses 100% of the available capacity and is more efficient.

like image 43
cdonner Avatar answered May 19 '26 11:05

cdonner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!