Base64 Encode in JavaScript
Encode a string to Base64 in JavaScript with btoa() in the browser or Buffer in Node.js. Check your result with the encoder before shipping.
Part of the free Base64 Encoder. Runs in your browser — nothing is uploaded.
Base64 Encode in JavaScript
Browsers provide btoa() for ASCII strings and Node.js provides Buffer. Use the encoder to confirm what your code should output, then copy the matching snippet.
Worked example: btoa and Buffer give the same output
Code
btoa("Hello, World!") // Buffer.from("Hello, World!").toString("base64")Result
SGVsbG8sIFdvcmxkIQ==
Practical tip
btoa() only handles Latin-1. For arbitrary text, use TextEncoder to get UTF-8 bytes, or Buffer in Node.js.
How to use this Base64 Encoder
- 1Use the live tool above — it runs entirely in your browser and never uploads your data.
- 2Paste the sample from the worked example, or use your own input.
- 3Copy the result, then adapt the same steps in your editor, script, or pipeline.
Base64 Encode in JavaScript FAQs
What is the Node.js equivalent of btoa?
Buffer.from(str, "utf8").toString("base64") for encoding. Node 16+ also provides a global btoa for Latin-1 strings.
How do I decode in JavaScript?
Use atob(encoded) in the browser or Buffer.from(encoded, "base64").toString("utf8") in Node.js.
More Base64 Encoder pages
- Encode a String to Base64Encode any text string to Base64 online. Paste your text and copy the result instantly. Supports UTF-8, free and processed in your browser.
- Base64 Encode UTF-8 Text and EmojiEncode Unicode text, accents and emoji to Base64 correctly. Avoid the btoa "Invalid character" error by encoding as UTF-8 first.
- Base64URL Encoder (URL-Safe Base64)Encode text to URL-safe Base64 (Base64URL) with - and _ instead of + and /, and no padding. The format used in JWTs and URLs.
- HTTP Basic Auth Header GeneratorGenerate an HTTP Basic Authorization header by Base64-encoding username:password. Build the header for curl, fetch and Postman.
- Encode JSON to Base64Encode a JSON object to Base64 for headers, query strings and config values. Paste JSON and copy the encoded string. Free and local.
- Base64 Encode a URLBase64 encode a URL to pass it safely as a parameter, hide it from casual reading or store it in a single token. Use Base64URL for safer links.
- Base64 MIME Encoding With 76-Character LinesMIME Base64 wraps lines at 76 characters. See what wrapped output looks like for email attachments and PEM-style data.
- Base64 Encode in PythonEncode a string to Base64 in Python with base64.b64encode. Remember to encode to bytes first and decode the result. Verify with the online encoder.
- Base64 Encoding Without PaddingEncode to Base64 without = padding characters. See when padding is optional, how to add it back, and why JWTs omit it.