How to convert MP3 to Base64
- Drop an
.mp3file on the box or pick it with the file picker. - Listen in the preview to confirm the clip.
- Keep Output as on Data URI for HTML and JavaScript, or switch to Plain Base64 or JSON for an API.
- Press Copy output, or Save as .txt for long files.
Length per bitrate
An MP3’s size is its bitrate times its duration, and Base64 makes it a third longer. Figures below are for the audio data alone, without tags:
| Bitrate | 1 second | 10 seconds | 1 minute |
|---|---|---|---|
| 64 kbps | 10,668 chars | 106,668 chars | 640,000 chars |
| 128 kbps | 21,336 chars | 213,336 chars | 1,280,000 chars |
| 192 kbps | 32,000 chars | 320,000 chars | 1,920,000 chars |
| 320 kbps | 53,336 chars | 533,336 chars | 3,200,000 chars |
For a notification sound or a spoken prompt, 64 kbps mono is usually plenty and keeps the string short. Re-export the clip at a lower bitrate in an audio editor before encoding if it is longer than you need.
The ID3 tag can be most of the file
MP3 files from music libraries carry an ID3v2 tag at the start, and that tag often contains embedded cover art. A two-second sound effect can come with a cover image that is larger than the audio itself, and all of it goes into the Base64.
A tagged file’s output starts with SUQz. SUQzBA means ID3 version 2.4 and SUQzAw version 2.3. If the file is meant for a UI sound or an API, remove the tags with an audio editor or tag editor, then encode the clean file. The meter under the output shows the difference.
Using a Base64 MP3
In HTML:
<audio controls src="data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2..."></audio>
In JavaScript, a data URI works anywhere a URL does:
const ping = new Audio("data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2...");
document.querySelector("#send").addEventListener("click", () => ping.play());
play() must run after a user gesture such as a click, or the browser blocks it.
For JSON APIs, use Plain Base64 unless the API documents a data URI. Speech-to-text services in particular usually want bare Base64 plus a separate field for the audio format.
Common problems
- The player stays silent. Check that the data URI begins with
data:audio/mpeg;base64,and that URL-safe and Wrap at 76 are off. URL-safe characters are not valid in adata:URL, and line breaks end a JavaScript string literal. - The duration is wrong or seeking jumps. Variable-bitrate MP3s without a proper header can confuse players. This comes from the file itself; re-export it with an audio editor.
- You need the file back. Base64 to MP3 decodes the string and lets you play or download it. For other formats see Audio to Base64.
FAQ
What is the correct MIME type for a Base64 MP3?
audio/mpeg. You will see audio/mp3 in some code, but the registered type is audio/mpeg, and APIs that validate the type expect it.
Why does my MP3 Base64 start with SUQz?
SUQz is ID3, the start of an ID3v2 tag with title, artist and maybe cover art. MP3 files without a tag start directly with an audio frame, which encodes to // followed by a letter such as //uQ or //OQ.
How many characters is one minute of MP3 in Base64?
At 128 kbps a minute of audio is 960,000 bytes, which encodes to 1,280,000 characters. At 64 kbps it is half that. Tags and cover art come on top.