title: Is there any significant disadvantage in storing base64 in a SQL Server database over storing the same data as hexadecimal?
body: <p>Most data that is of the nature of hash values* (see note below) are all stored in a relational database such as SQL Server in either <a href="https://docs.microsoft.com/en-us/sql/t-sql/data-types/binary-and-varbinary-transact-sql?view=sql-server-ver15" rel="nofollow noreferrer"><code>BINARY</code></a> data type or in <a href="https://docs.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?view=sql-server-ver15" rel="nofollow noreferrer"><code>CHAR</code></a> data type.</p>
  
  <p>When stored in <code>CHAR</code>, <a href="https://stackoverflow.com/a/247627/303685">as a practice</a> and not as the database implementation, they are <em>mostly</em> stored as hexadecimals. That is, they are stored by the <em>user of the database</em> or the <em>author of the code that uses the database</em> in <em>hexadecimals</em>, and not <em>by the database itself</em>.</p>
  
  <p>So, my question is: why? Why store it only as hexadecimal? I'd like to store something of this nature in a <code>CHAR</code> field as base64.</p>
  
  <p>It would take much less space, too.</p>
  
  <p><strong>Stored as ASCII Plain Text</strong></p>
  
  <p>For e.g. to store the text "Hello" in plain ASCII inside a <code>CHAR</code> type column, assuming that string was the only string I wanted to store and so I took a fixed length column, would take <code>CHAR(6)</code> (counting one <code>CHAR</code> for the null character).</p>
  
  <p><strong>Stored in the Hexadecimal Notation</strong></p>
  
  <p>Storing the same in hexadecimal would take a <code>CHAR(11)</code>, i.e. 10 hexadecimal characters plus 1 for the null character.</p>
  
  <p><strong>Stored in the base64 notation</strong></p>
  
  <p>Storing the same in base64 would take only a <code>CHAR(8)</code>, i.e. 5 characters + 1 null character taking up a total of 6 bytes in ASCII encoding, which equals 48 bits, which when translated into base64, would need only (48 / 6 = 8) 8 characters to express including the null character.</p>
  
  <p>So, is there any reason why the hexadecimal notation is preferred? More importantly, is there any disadvantage I might be overlooking in storing data in the base64 notation?</p>
  
  <hr>
  
  <p><strong>*Data that is of similar nature:</strong></p>
  
  <p>Data of the nature of has values, message digests, or checksums, or salts (for either hash functions or password based key derivation functions or for keys for encryption algorithms), etc.</p>