title: Why does a binary serialization of a float use 55 bytes?
body: <p>I have a task to take millions of floats and store them in the database in batches of 5,000, as binary.  This is forcing me to learn interesting things about serialization performance.</p>
  
  <p>One of the things that surprises me is the size of the serialized data, which is a factor of ten above what I expected.  This test shows me that a four-byte float is serialized to 55 bytes and an eight-byte double to 59 bytes.</p>
  
  <p>What is happening here?  I expected it to simply split the float value into its four bytes.  What are the other 51 bytes?</p>
  
  <pre><code>private void SerializeFloat()
  {
      Random rnd = new Random();
      IFormatter iFormatter = new BinaryFormatter();
  
      using (MemoryStream memoryStream = new MemoryStream(10000000))
      {
          memoryStream.Capacity = 0;
          iFormatter.Serialize(memoryStream, (Single)rnd.NextDouble());
          iFormatter.Serialize(memoryStream, rnd.NextDouble());
      }
  }
  </code></pre>