Base64 Encoder & Decoder

Free online tool to encode and decode text, images, and files to Base64 format instantly.

Base64 Encoder

Encode text or files into Base64 format. Select character encoding for text.

Select the character encoding of the input text (UTF-8 is common). Browser support for encodings other than UTF-8 may vary.

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into a sequence of printable ASCII characters. It works by taking every 3 bytes (24 bits) of binary data and representing them as 4 ASCII characters from a 64-character alphabet (A–Z, a–z, 0–9, +, /). The result is text that's safe to transmit through systems designed to handle only text — like HTTP headers, JSON bodies, email attachments (MIME), and URLs.

The term "Base64" refers to the encoding base: 64 unique characters can each represent 6 bits (2⁶ = 64), so every 3 bytes of binary data maps to exactly 4 Base64 characters. This increases data size by approximately 33%, which is the trade-off for universal text compatibility.

How Base64 Encoding Works

Step 1 — Split into 3-byte chunks: The input binary data is divided into groups of 3 bytes (24 bits each). If the input length isn't divisible by 3, padding characters (=) are added.

Step 2 — Split into 6-bit groups: Each 24-bit chunk is divided into four 6-bit groups.

Step 3 — Map to characters: Each 6-bit value (0–63) maps to a character in the Base64 alphabet. For example: 0→A, 25→Z, 26→a, 51→z, 52→0, 61→9, 62→+, 63→/.

Step 4 — Add padding: If the input doesn't divide evenly into 3-byte chunks, = padding is added to make the output length a multiple of 4.

Example: The string "Man" (ASCII: 77, 97, 110) encodes to "TWFu". The string "Ma" (2 bytes) encodes to "TWE=" (one = padding). "M" (1 byte) encodes to "TQ==" (two = padding).

Common Use Cases for Base64

  • Data URIs: Embed images directly in HTML/CSS — src="data:image/png;base64,iVBORw0KGgo..." — eliminating extra HTTP requests
  • HTTP Basic Authentication: Credentials are Base64 encoded in the Authorization header: Authorization: Basic dXNlcjpwYXNz
  • Email Attachments (MIME): Binary files (PDFs, images) are Base64 encoded in email MIME parts so they survive text-only email transport
  • JSON APIs: Store and transmit binary data (images, certificates, keys) in JSON payloads which only accept text
  • CSS backgrounds: Small icons and SVGs embedded as Base64 data URIs in stylesheets reduce HTTP requests
  • JWT Tokens: The header and payload of JWT tokens are Base64Url encoded (a URL-safe variant of Base64)
  • Certificate encoding: X.509 certificates (PEM format) are Base64 encoded binary DER data

Base64 vs Base64URL

Standard Base64 uses + and / as characters 62 and 63, plus = for padding. These characters have special meaning in URLs, causing problems when Base64 data appears in query strings or path segments.

Base64URL replaces + with - and / with _, and often omits = padding. This makes it safe for use in URLs and HTTP headers. JWTs, OAuth tokens, and URL-safe data encoding use Base64URL.

Our tool uses standard Base64. If you need Base64URL for JWTs, use our JWT Encoder.

Security Considerations

Base64 is NOT encryption. Anyone with a Base64 encoded string can trivially decode it back to the original data — it's just a different representation, not a secret. Never use Base64 to "hide" sensitive data like passwords or private keys.

Don't confuse encoding with encryption: If you need to protect sensitive data, encrypt it first (AES, RSA), then optionally Base64 encode the ciphertext for transport. The encoding layer adds no security.

Avoid Base64 in URLs for security tokens: While Base64URL is used in JWTs, the payload is still readable. JWTs provide integrity (signature), not confidentiality. Store them securely (httpOnly cookies) and set short expiration times.

Performance Tips

Size overhead: Base64 encoding increases data size by ~33%. For large files, consider whether Base64 is necessary — binary HTTP responses (multipart/form-data) are more efficient for file uploads.

Data URI limits: Browsers have limits on data URI sizes. For images larger than ~10KB, serving them as separate HTTP requests is typically faster than Base64 embedding (especially with HTTP/2 which handles multiple requests efficiently).

Streaming large files: For files above a few MB, chunked processing or server-side Base64 conversion is more memory-efficient than loading the entire file in the browser.

Frequently Asked Questions

Why does Base64 output end with = or ==?

The = padding characters appear when the input length isn't divisible by 3. One = means the original data had 2 bytes remaining (not 3), two == means 1 byte remaining. Padding ensures the output length is always a multiple of 4 characters.

Can Base64 encode any type of file?

Yes. Base64 works on raw bytes, so it can encode any binary data regardless of file type — images, PDFs, executables, audio, video, or any document. The encoding is file-type agnostic.

How do I decode Base64 in JavaScript?

Use atob() for simple text: atob("SGVsbG8=") returns "Hello". For binary data or files, use Uint8Array with atob() to handle non-UTF-8 bytes correctly. For Base64URL, replace - with + and _ with / first.

Is Base64 the same across all programming languages?

The Base64 alphabet and algorithm are standardized (RFC 4648), so output is identical across Python, JavaScript, Java, PHP, and other languages. However, line-break behavior varies: MIME Base64 wraps at 76 characters, while most modern implementations produce continuous output. Our tool produces unformatted Base64.

What character encodings does this tool support?

For text input, the tool supports UTF-8 (recommended for most cases), ISO-8859-1 (Latin-1), and Windows-1252. UTF-8 handles all Unicode characters including emoji and international text. For file input, the raw binary bytes are encoded regardless of the file's internal encoding.