title: Predict the byte size of a base64 encoded byte[]
body: <p>I'm trying to predict the size string representation of a base64 encoded byte array.</p>
  
  <p>I've come up with the formula below, however the length of the actual <code>encodedString</code> is 4 larger than the <code>base64EncodedSize</code>. </p>
  
  <p>The whole idea here is to calculate/predict what the encoded string size would be for a given <code>byte[]</code>. I would prefer not to convert the <code>byte[</code>] to a base 64 string just to determine it's length.</p>
  
  <pre><code>FileInfo pdfFile = new FileInfo(@"C:\TEMP\1.pdf");
  
  long originalSizeInBytes = pdfFile.Length;
  
  String encodedString = Convert.ToBase64String(File.ReadAllBytes(pdfFile.FullName));
  
  long base64EncodedSize = (originalSizeInBytes / 3) * 4;
  
  ----------------------------------------------------------------------------------
  - Results -
  -----------------------------------------------------------------------------------
    originalSizeInBytes                           913663  long
    base64EncodedSize                             1218216 long
    encodedString.Length                          1218220 int
    base64EncodedSize                             1218216 long
    encodedString.Length - base64EncodedSize      4       long
  </code></pre>