How to Encode Base64
Base64 encoding is one of the most widely used data representation formats on the web. From embedding images in CSS to transmitting binary data over JSON APIs, Base64 is a tool every developer should understand. This guide covers what Base64 is, how it works, and how to encode and decode it instantly with an online tool.
What Is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 ASCII characters: uppercase letters A–Z, lowercase letters a–z, digits 0–9, and the symbols+ and /. A padding character = is used when the input length is not a multiple of 3 bytes.
The primary purpose of Base64 is to ensure that binary data can be safely transported over text-based protocols like HTTP, email (MIME), and JSON without corruption.
When Should You Use Base64?
- Data URLs. Embed images directly in HTML or CSS using
data:image/png;base64,...to avoid extra HTTP requests. - API authentication. HTTP Basic Auth sends credentials as
Basic base64(username:password). - Email attachments. MIME encoding uses Base64 to attach binary files to email messages.
- JSON transport. When you need to include binary data (images, files) inside a JSON payload.
How to Encode Base64 Step by Step
- 1Prepare your input. Copy the text or file content you want to encode. It can be any string or binary data.
- 2Paste into the encoder. Use the ToolStack Base64 Encoder and paste your input into the text area.
- 3Copy the output. The encoded Base64 string appears instantly. You can copy it to your clipboard with one click.
Base64 in JavaScript
Most languages have built-in Base64 support. In JavaScript:
// Encode
const encoded = btoa("Hello, World!")
// "SGVsbG8sIFdvcmxkIQ=="
// Decode
const decoded = atob("SGVsbG8sIFdvcmxkIQ==")
// "Hello, World!"For UTF-8 strings, wrap with encodeURIComponent and decodeURIComponent to handle multi-byte characters correctly.
Try It: Encode Base64 Online
Use our free, client-side Base64 Encoder to encode any text or data instantly. Your data never leaves your browser.
Open Base64 Encoder