encode | file | copy

> base64 encoder | text | file <

// Encode text, UTF-8, JSON, images, or any file into Base64 — standard, URL-safe, with or without padding. 100% client-side. Drag-and-drop a file up to 100 MB.

0 chars
[TEXT]

Text & UTF-8 Encoding

Encodes plain text, UTF-8 multi-byte characters, emoji, JSON, XML, and HTML. Uses native TextEncoder for accurate byte-level UTF-8.

[FILE]

File to Base64

Drag-and-drop or click to upload any file (PNG, JPG, PDF, ZIP, binary) up to 100 MB. Outputs pure Base64 — copy directly into Data URIs, JSON APIs, or HTML.

[VARIANTS]

URL-safe + No-Padding

Toggle <code>--url-safe</code> to produce JWT/OAuth-compatible Base64 using the <code>-_</code> alphabet. Toggle <code>--no-padding</code> to drop trailing <code>=</code>.

// HOW BASE64 ENCODING WORKS

Base64 Encoding Algorithm:

Base64 takes 3 input bytes (24 bits), splits them into four 6-bit groups, and maps each group to a character in the 64-character alphabet (A-Z a-z 0-9 + /). When the input length isn't a multiple of 3, = padding is appended so the output length is a multiple of 4. URL-safe Base64 substitutes - and _ for + and / — safe in URLs, filenames, and JWT without extra percent-encoding.

Encode Example:

Text   : Hi!
Bytes  : 72 105 33
Bits   : 01001000 01101001 00100001
         010010 000110 100100 100001
B64    : S     G     k     h
Output : SGkh

Common Encoding Scenarios:

  • >Embedding images inline in HTML/CSS (Data URIs)
  • >Producing MIME email attachments (RFC 2045 §6.8)
  • >Constructing HTTP Basic Auth headers (Authorization: Basic ...)
  • >Creating JWT header/payload (URL-safe, no padding)
  • >Encoding binary payloads for JSON APIs that can't carry raw bytes
  • >Building OAuth 2.0 code verifiers and S3 presigned URLs

// FREQUENTLY ASKED QUESTIONS

How do I encode text to Base64 online?

Type or paste your text into the INPUT area above. Auto-encode is on by default — the Base64 result appears in the OUTPUT box as you type. Click [ENCODE] or press Ctrl/Cmd + Enter to trigger encoding manually. Toggle --url-safe or --no-padding depending on where the Base64 will be used (JWT, OAuth, URLs → both on). Everything runs locally in your browser: no uploads, no logs, no network requests tied to your input.

How do I encode a file (PNG, JPG, PDF, ZIP, binary) to Base64?

Click the [upload file] button below the input area and pick a file up to 100 MB. The encoder reads it with FileReader.readAsArrayBuffer, streams the bytes through btoa in 32 KB chunks (so large files don't crash the browser), and writes the full Base64 into the OUTPUT box. For larger files, use a command-line encoder: base64 < input.bin > output.txt (macOS/Linux), or PowerShell: [Convert]::ToBase64String([IO.File]::ReadAllBytes('input.bin')).

If you want the Base64 formatted as a Data URI (e.g. data:image/png;base64,...), prepend the MIME type and ;base64, to the output, or use our dedicated Image to Base64 tool, which outputs ready-to-paste Data URIs for PNG, JPG, GIF, WebP, and SVG.

What's the difference between standard, URL-safe, and no-padding Base64?

All three are defined in RFC 4648:

Standard Base64 (§4) uses the alphabet A-Z a-z 0-9 + / with = padding. Output length is always a multiple of 4. Safe for MIME, HTTP Basic Auth, and JSON string values.

URL-safe Base64 (§5) replaces + with - and / with _. Required when Base64 is placed in URL paths, query parameters, filenames, or JWT segments — the standard +/ characters would otherwise need percent-encoding.

No-padding (both §4 and §5, base64url unpadded) drops trailing = characters. The length is no longer a multiple of 4, but decoders can compute the original length from the remainder mod 4. Used by JWT (base64url per RFC 7515), WebAuthn, and some CBOR/COSE implementations.

Decoders must be told which variant to expect — our Base64 Decoder auto-detects all three.

How do I encode Base64 in code (JavaScript, Python, PHP, Go, Java)?

Every major language and runtime ships with Base64 encoding. Copy-paste-ready snippets:

JavaScript (browser):
btoa('Hello') // SGVsbG8=
// For UTF-8:
btoa(String.fromCharCode(...new TextEncoder().encode(s))) // UTF-8 safe


Node.js:
Buffer.from('Hello', 'utf-8').toString('base64') // SGVsbG8=
Buffer.from(bytes).toString('base64url') // URL-safe, no pad


Python:
import base64
base64.b64encode(b'Hello').decode() # SGVsbG8=
base64.urlsafe_b64encode(b'Hello').decode().rstrip('=') # URL-safe no-pad


PHP: base64_encode('Hello')
Ruby: Base64.strict_encode64('Hello') / Base64.urlsafe_encode64('Hello')
Go: base64.StdEncoding.EncodeToString([]byte("Hello")) / base64.URLEncoding.EncodeToString(...) / base64.RawURLEncoding.EncodeToString(...) (no pad)
Java: Base64.getEncoder().encodeToString("Hello".getBytes(StandardCharsets.UTF_8))
C#: Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello"))
Rust: base64::engine::general_purpose::STANDARD.encode("Hello")

Shell (macOS/Linux): echo -n 'Hello' | base64SGVsbG8=. Use base64 -w 0 on Linux to suppress 76-column line wrapping.

How big is the Base64 output compared to the input? When should I NOT use Base64?

Base64 output is ~33% larger than the input: every 3 input bytes become 4 output characters. Exact formula: ceil(n / 3) × 4 including padding, or ceil(n × 4 / 3) without. Plus a few more bytes of overhead if you line-wrap at 76 columns (MIME) or 64 columns (PEM).

Examples:
• 1 KB binary → ~1.37 KB Base64
• 100 KB image → ~137 KB Data URI
• 1 MB PDF → ~1.37 MB Base64 in JSON

When to avoid Base64:
Large file transfers: a 10 MB image embedded as Base64 in HTML becomes 13.7 MB of parsed text, blocks the main thread, and can't be cached separately. Prefer <img src="/assets/photo.png">.
Performance-critical APIs: a 500 KB Base64 payload in JSON parses ~2-3× slower than an equivalent binary endpoint.
As a security measure: Base64 is not encryption — anyone can decode it. Use AES-GCM or similar for confidentiality.
Database BLOBs: store raw bytes as BLOB/BYTEA, not Base64 text, to save 33% storage and avoid encode/decode round-trips.

How do I encode text to URL-safe Base64 for a JWT or OAuth parameter?

JWT (RFC 7515) and OAuth PKCE (RFC 7636) both use URL-safe Base64 without padding, often called base64url. To produce it in this tool: enable both --url-safe and --no-padding checkboxes, then encode your text.

Programmatic equivalents:
• JavaScript: btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
• Node.js: Buffer.from(s).toString('base64url')
• Python: base64.urlsafe_b64encode(s.encode()).decode().rstrip('=')
• Go: base64.RawURLEncoding.EncodeToString([]byte(s))
• Java: Base64.getUrlEncoder().withoutPadding().encodeToString(bytes)

Common JWT fields that need base64url: the three dot-separated segments (header, payload, signature), OAuth PKCE code_verifier/code_challenge, WebAuthn challenges, Web Push p256dh/auth keys, and Google's Request.state parameters.

A common bug is sending a JWT with standard Base64 (+/) — APIs will reject it as malformed because the + gets URL-decoded to a space in transit.

Can I encode a Data URI (data:image/png;base64,...) with this tool?

Yes, with one caveat. This encoder produces the Base64 portion of a Data URI — the part after ;base64,. To build a complete Data URI, prepend:

data:<mime-type>;base64,<encoded-output>

Common MIME types:
data:image/png;base64,... — PNG image
data:image/jpeg;base64,... — JPEG image
data:image/svg+xml;base64,... — SVG (or use data:image/svg+xml;utf8, without Base64 — usually smaller)
data:application/pdf;base64,... — PDF file
data:application/font-woff2;base64,... — font embed
data:text/plain;charset=utf-8;base64,... — Base64-wrapped text

For images and SVGs, the Image to Base64 tool emits the complete Data URI ready to paste into CSS background-image, inline <img src="...">, or <object data="..."> tags.

Size warning: Data URIs over 20-30 KB hurt LCP (Largest Contentful Paint) because the browser can't preload them — keep inline Base64 images small, and prefer regular <img> with loading="lazy" for larger assets.

Is this Base64 encoder safe for sensitive text and API keys?

Yes — nothing leaves your browser. The encoder runs entirely in JavaScript using native btoa(), TextEncoder, and FileReader APIs. There are no network calls on the input content, no telemetry, no logging, no third-party analytics on what you encode. You can open the Network tab in DevTools while encoding and observe zero related requests.

However, Base64 is not encryption — it's a reversible encoding, and anyone with the output can decode it. So:
Don't paste production secrets into chat, screenshots, or logs even in encoded form.
• For HTTP Basic Auth, the Base64 Authorization: Basic header is only secure over TLS (HTTPS). Over plaintext HTTP, it's trivially sniffable.
• For real confidentiality, use AES-GCM, age, sops, or a KMS — then Base64-encode the ciphertext for transport if needed.

For strict data-exfiltration policies, save this page offline (Cmd/Ctrl + S). The encoder works fully air-gapped after one load since there's no server dependency.

Can I encode very large files to Base64? What are the browser limits?

The encoder supports files up to 100 MB via the hard limit in the file handler — large enough for most images, PDFs, ZIP archives, and even short videos. Performance targets:

< 1 MB: encoding completes in <50 ms, no UI freeze.
1 – 10 MB: 100-500 ms depending on CPU. Browser stays responsive because we encode in 32 KB chunks.
10 – 100 MB: 2-15 seconds. Output textarea may lag slightly when you paste/scroll such huge Base64 strings. Consider downloading the output as a .txt file from DevTools if needed.
> 100 MB: blocked — browser memory overhead (input bytes + binary string + Base64 string ≈ 3-4× the file size) risks tab crashes. Use:

# macOS / Linux
base64 -i huge.bin -o huge.b64

# Windows PowerShell
$bytes = [IO.File]::ReadAllBytes('huge.bin')
[IO.File]::WriteAllText('huge.b64', [Convert]::ToBase64String($bytes))


For streaming/multi-GB workflows, see encoding large files to Base64 for a chunked approach with Node.js/Python that avoids loading everything into memory.

What character encoding does this Base64 encoder use for text input?

This encoder uses UTF-8, the same encoding used by the modern web, JSON, Linux, macOS, and almost all programming languages by default. Under the hood, text is passed through new TextEncoder().encode(input), which always produces UTF-8 bytes, and only then Base64-encoded.

Why this matters: the older JavaScript btoa() function only handles Latin-1 and throws InvalidCharacterError on characters like é, , or 😀. Our wrapper handles the UTF-8 conversion for you, so emoji, Chinese, Japanese, Korean, Arabic, Cyrillic, and any Unicode code point encode correctly.

If you need a different encoding:
UTF-16 LE (Windows-native): rare — usually a sign of legacy interop. Use new TextEncoder({ fatal: true }).encode(s) anyway and convert upstream.
ISO-8859-1 / Latin-1: manually map code points 0-255 to bytes before encoding.
GB18030, Shift_JIS, EUC-KR: use a library like iconv-lite in Node.js to transcode first.

A subtle gotcha: if your source data is already in a non-UTF-8 encoding (e.g., reading a legacy MySQL dump), decode it first with the correct codec, then re-encode to UTF-8 before Base64 — otherwise the decoded Base64 will preserve mojibake.

// RELATED TOOLS

// OTHER LANGUAGES