# Window: atob() method



The **`atob()`** method of the [Window](https://developer.mozilla.org/en-US/docs/Web/API/Window) interface decodes a
string of data which has been encoded using [Base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64) encoding. You can use
the [Window.btoa()](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa) method to encode and transmit
data which may otherwise cause communication problems, then transmit it and use the
`atob()` method to decode the data again. For example, you can encode,
transmit, and decode control characters such as [ASCII](https://developer.mozilla.org/en-US/docs/Glossary/ASCII) values 0 through 31.

Also consider using the [Uint8Array.fromBase64()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64%28%29) method, which creates a `Uint8Array` object from a base64-encoded string. It results in a byte array, which is easier to work with than a string containing raw bytes.

## Syntax

```js-nolint
atob(encodedData)
```

### Parameters

- `encodedData`
  - : A base64-encoded string, using the alphabet produced by [Window.btoa()](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa).

### Return value

A binary string containing raw bytes decoded from `encodedData`. Strings in JavaScript are encoded as [UTF-16](https://developer.mozilla.org/en-US/docs/Glossary/UTF-16), so this means each character must have a code point less than 256, representing one byte of data.

### Exceptions

- `InvalidCharacterError` [DOMException](https://developer.mozilla.org/en-US/docs/Web/API/DOMException)
  - : Thrown if `encodedData` is not valid base64.

## Examples

```js
const encodedData = window.btoa("Hello, world"); // encode a string
const decodedData = window.atob(encodedData); // decode the string
```

For more examples, see the [Window.btoa()](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa) method.

## Specifications

## Browser compatibility

## See also

- [A polyfill of `atob`](https://core-js.io/docs/features/web-standards/atob-btoa) is available in [`core-js`](https://core-js.io/)
- [`data` URLs](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data)
- [WorkerGlobalScope.atob()](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/atob): the same method, but in worker scopes.
- [Window.btoa()](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa)
- [Uint8Array.fromBase64()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64%28%29)
