# Convert a base64 encoded string to an Uint8Array

Decode base64 into its byte values.

Canonical: https://1loc.dev/string/convert-a-base64-encoded-string-to-an-uint8-array/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function base64ToBytes(base64) { return Array.from(atob(base64), char => char.charCodeAt(0)); }
```

## Input

```json
"SGVsbG8="
```

## Expected output

```json
[
  72,
  101,
  108,
  108,
  111
]
```

## Edge case

Input:
```json
""
```
Output:
```json
[]
```

## 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 lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/convert-a-base64-encoded-string-to-an-uint8-array.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: 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.
