Base64 Encoder

Base64 Encoder is an online tool to convert text or files to base64. It encodes binary data so that it can be stored and transferred safely. The encoded text does not contain non-printable characters. It only contains ASCII characters. So, you don't have to worry about control characters messing with the syntax of the text formats such as HTML. You can also use this tool to encode audio files.

All processing happens on the client-side, locally in your browser. No data is uploaded.

Paste plain text below
Base64 encoded text

Settings

How the input is converted. Each is explained below.

The output format for the Base64 string

Use cases

Convert MP3 to Base64

Using this tool, you can convert MP3 files to Base64 and transmit the binary data over a text format such as HTML.

  1. Click the Select File button and choose the MP3.
  2. Choose the output format, such as HTML Audio.
  3. Click the Encode button.
  4. The base64 encoded MP3 file will be in the output.

History

  • 2021-10-11Support for multiple output formats
  • 2018-04-01Improved handling of binary files
  • 2017-10-27Support for uploading & encoding binary files
  • 2017-08-20Released

Settings explained

Output format

The output format wraps the Base64 in HTML tags, attributes, JSON, and XML. It supports the following output formats.

Plain text
Plain text is the default format, and it only generates the base64 string. You have the additional option to wrap long lines by splitting them.
Data URI
Generates a Data URI, which also contains the mime type. This URI forms the basis of a lot of the following output formats.
HTML Audio
This audio to base64 output format generates an HTML audio tag.
HTML Embed
Embeds the output and mime type in an HTML EMBED tag.
HTML HyperLink
Embeds the output in the HREF attribute of an HTML Anchor tag.
HTML Iframe
Embeds the output in the SRC attribute of an HTML iframe tag.
HTML Object
Embeds the output and mime type in an HTML object tag.
HTML Source
Embeds the output in the SRC attribute of an HTML source tag.
JavaScript Audio
Outputs a JavaScript code that can play the audio when executed.
JavaScript Popup
Generates a JavaScript code that opens the content as a popup in the browser on click.
JSON
Generates a JSON text with the mime type and base 64 string as properties of an audio node.
XML
Generates an XML markup with an audio element.
Split long lines

Wraps the lines after 75 characters for better viewing when turned on. However, the Copy output button still copies the text as a single line.

Split long lines on
TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQgb2YgdGhlIHByaW50aW5nIGFuZCB0eX
Blc2V0dGluZyBpbmR1c3RyeS4gTG9yZW0gSXBzdW0gaGFzIGJlZW4gdGhlIGluZHVzdHJ5J3M=
Split long lines off
TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQgb2YgdGhlIHByaW50aW5nIGFuZCB0eXBlc2V0dGluZyBpbmR1c3RyeS4gTG9yZW0gSXBzdW0gaGFzIGJlZW4gdGhlIGluZHVzdHJ5J3M=

About Base64

We use Base64 encoding to represent binary data in ASCII characters. It consists of 64 characters, including letters, numbers, and two symbols plus (+) and slash (/). Additionally, the equals sign (=) is the pad character at the end. The typical usage is to embed image data within scripts such as CSS. The cool thing about Base64 is that most programming languages support it natively using built-in APIs. You can decode and encode binary data without importing any external libraries.

In C#, the ToBase64String method of System.Convert class does this. This method takes a byte array as input and returns the result in ASCII string format. Typically, this is some binary data that we cannot transfer over the wire without corruption. However, you can also convert text into byte[] and then encode it using base64. One must question why this is needed because it is not the intended use of the Base-64 encoding scheme. In this form, you are just wasting bytes to represent your text data. Use Base64 strings if you want to perform binary to text encoding and transmit your data safely.

Check out the Programming languages section below for a list of APIs for other languages. Read more at Wikipedia.

How to do Base64 encoding and decoding in various programming languages

LanguageEncodeDecodeExampleDocumentation
C#System.Convert.ToBase64String()System.Convert.FromBase64String()ExampleDocumentation
VB .NETSystem.Convert.ToBase64String()System.Convert.FromBase64String()ExampleDocumentation
Java 8+java.util.Base64.getEncoder().encode()java.util.Base64.getDecoder().decode()ExampleDocumentation
Java 7 or lessorg.apache.commons.codec.binary.Base64.encodeBase64()org.apache.commons.codec.binary.Base64.decodeBase64()ExampleDocumentation
JavaScriptbtoa()atob()btoa()atob()Documentation
Pythonbase64.b64encode()base64.b64decode()ExampleDocumentation
RubyBase64.encode64()Base64.decode64()ExampleDocumentation

Example substitutions

Each 6-bit value and the character it is written as.

  • 0A
  • 1B
  • 2C
  • 3D
  • 4E
  • 5F
  • 6G
  • 7H
  • 8I
  • 9J
  • 10K
  • 11L
  • 12M
  • 13N
  • 14O
  • 15P
  • 16Q
  • 17R
  • 18S
  • 19T
  • 20U
  • 21V
  • 22W
  • 23X
  • 24Y
  • 25Z
  • 26a
  • 27b
  • 28c
  • 29d
  • 30e
  • 31f
  • 32g
  • 33h
  • 34i
  • 35j
  • 36k
  • 37l
  • 38m
  • 39n
  • 40o
  • 41p
  • 42q
  • 43r
  • 44s
  • 45t
  • 46u
  • 47v
  • 48w
  • 49x
  • 50y
  • 51z
  • 520
  • 531
  • 542
  • 553
  • 564
  • 575
  • 586
  • 597
  • 608
  • 619
  • 62+
  • 63/
  • pad=

Related tools