Related Tools
Base64 Encode
Encode a string as base64:
Base64 (MIME) Encode Tool
Use this free tool to turn binary data into text (encode) or text into binary (decode).
To allow binary data to be transmitted with textual data it must be encoded. An example of this is an attachment in an email. This is done via the MIME implementation of Base64. The MIME implementation uses the characters A-Z
, a-z
, and 0-9
for the initial 62 values that it can use to encode data.
For example, the text:
Dan's Tools are cool!
RGFuJ3MgVG9vbHMgYXJlIGNvb2wh
What is Base64 encoding?
The term Base 64 is generic, and there are many implementations. MIME, which stands for Multi-Purpose Internet Mail Extensions, is the most common that is seen today. It is used to transmit attachments via email over the Simple Mail Transfer Protocol (SMTP). Other examples of Base64 encoding are Radix-64 and YUI's Y64. Encoding data in Base64 results in it taking up roughly 33% more space than the original data.
MIME Base64 encoding is the most common, and is based on the RFC 1420 specification. It also uses a =
character at the end of a string to signify whether the last character is a single or double byte.
When and why would you use Base64 encoding?
You should use Base64 whenever you intend to transmit binary data in a textual format.
Code Examples
Language | Encode | Decode | Notes |
---|---|---|---|
PHP | base64_encode($string); | base64_decode($string); | |
Perl | encode_base64($string); | decode_base64($string); | Requires use MIME::Base64; |
C# | System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(plainTextBytes)); | System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(base64EncodedData)); | |
Java | Base64.encodeBase64(string); | Base64.decodeBase64(string); | Requires import org.apache.commons.codec.binary.Base64; |
JavaScript | btoa(string); | atob(string); | <= IE9 is unsupported |
Ruby | Base64.encode64('string') | Base64.decode64(enc) | Requires require "base64" |
External Links
- More information about Base64 (Wikipedia)