Convert a base64 encoded string to an Uint8Array

Decode base64 into its byte values.

JavaScript Version 1.0.0 · MIT · .md

convert-a-base64-encoded-string-to-an-uint8-array.js
function base64ToBytes(base64) { return Array.from(atob(base64), char => char.charCodeAt(0)); }

Input & expected output

Input

"SGVsbG8="

Expected output

[
  72,
  101,
  108,
  108,
  111
]

The edge case

Input

""

Expected output

[]

Know the limits

  • Returns plain numbers so the lab can show them; wrap the result with Uint8Array.from in your code.
  • Oveyon’s /v1/send takes attachment content as base64 (up to 20 attachments, 15 MB in total); decode only what you need to inspect.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Convert a base64 encoded string to an uint8 array from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Returns plain byte values instead of a Uint8Array so results are JSON-representable; base64 alphabet and padding validated first. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.