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

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 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

Open the full Base64 Encoder tool →