title: What text encoding scheme do you use when you have binary data that you need to send over an ascii channel?
body: <p>If you have binary data that you need to encode, what encoding scheme do you use?</p>
  
  <p>I know about:</p>
  
  <ul>
  <li><a href="http://en.wikipedia.org/wiki/Hexadecimal" rel="nofollow noreferrer">Hex encoding</a>. Very simple, but quite verbose, expands one byte to two.</li>
  <li><a href="http://en.wikipedia.org/wiki/Base64" rel="nofollow noreferrer">Base 64</a>. Most common, not so verbose, expands three bytes to four.</li>
  <li><a href="http://en.wikipedia.org/wiki/Ascii85" rel="nofollow noreferrer">Base 85</a>. Not common, less verbose again, expands four bytes to five.</li>
  </ul>
  
  <p>Are there any other encoding schemes in common use? If so, what are there advantages and disadvantages?</p>
  
  <p><b>Edit</b>: This is useful, for example, when trying to store arbitrary data in a cookie. Cookies can only store text, not arbitrary data, so you need to convert it in some way, preferably with a way to convert it back. Further, assume that you are using a stateless server so that you cannot save the state on the server and just put an identifier into the cookie. Of course, if you do this you would also need some way of verifying that what the user is passing back to you is what you passed to the user, for example a signature.</p>
  
  <p>Also, since the current consensus is that you should use base64 since it is widespread, I will also point out that this <em>is</em> what I use... I am just curious if anyone used anything else, and if so, why.</p>
  
  <p><b>Edit</b>: Just in case someone stumbles across this, if you do want to use Base64 to store data in a cookie, you need to use <a href="http://en.wikipedia.org/wiki/Base64#URL%5Fapplications" rel="nofollow noreferrer">a modified Base64 implementation</a>. See <a href="https://stackoverflow.com/questions/2090009/what-text-encoding-scheme-do-you-use-when-you-have-binary-data-that-you-need-to-s/2090066#2090066">this answer</a> for the reason why.</p>