# From Base64

Decodes a Base64 string to raw binary data. Use it when a previous step or API returns Base64 and you need the original
bytes for file handling, further decoding, or another transform. Supports the same alphabet presets as
[To Base64](../to-base64/), optional stripping of non-alphabet characters, and strict validation. From Base64 lives in
the **Data format** category of the `fx` menu.

Alphabet rules follow [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648) (and related variants) when you pick a
matching preset.

## Parameters

| Parameter                 | Type    | Required | Default                             | Description                                                                                                                                                                                                                    |
| ------------------------- | ------- | -------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Input                     | string  | yes      | —                                   | Base64 text to decode.                                                                                                                                                                                                         |
| Alphabet                  | string  | yes      | `Standard (RFC 4648): A-Za-z0-9+/=` | Same alphabet used when the data was encoded. Presets include RFC 4648 standard and URL-safe, plus other common variants.                                                                                                      |
| Remove non-alphabet chars | boolean | yes      | `true`                              | When on, removes every character that is not in the chosen alphabet before decoding (for example spaces, newlines, or other separators in the Base64 text).                                                                    |
| Strict mode               | boolean | yes      | `false`                             | When on, rejects invalid input: length cannot be `4n+1`, padding (when the alphabet has a padding symbol) must appear only at the end in the correct form, and no non-alphabet characters may remain after optional stripping. |

`Input` is the primary Base64 string. **Alphabet**, **Remove non-alphabet chars**, and **Strict mode** are controls on
the function card.

## Returned value

| Type     | Description                                 |
| -------- | ------------------------------------------- |
| `binary` | The decoded raw bytes for the Base64 input. |

## Limitations

- Input must be a string. Non-string input raises `fromBase64: functionInput must be a string`.
- Alphabet must match the encoder. A URL-safe payload decoded with the standard alphabet (or the reverse) fails or
  produces wrong bytes.
- With **Strict mode** on, malformed length, bad padding, or leftover non-alphabet characters raise an error.
- With **Remove non-alphabet chars** off and separators in the text, decoding fails unless you clean the string first.

:::caution
Invalid Base64 for the chosen **Alphabet** and **Strict mode** stops evaluation with an error — fix the string or
options before re-running the step.
:::

## Examples

<details>
<summary>Decode a standard Base64 string</summary>

Decode the most common Base64 form back to bytes. Leave stripping on so whitespace in the string does not block
decoding.

1. Set **Input** to the Base64 string. Paste:

   ```text title="Input"
   aGVsbG8=
   ```

2. Leave **Alphabet** on `Standard (RFC 4648): A-Za-z0-9+/=`.
3. Leave **Remove non-alphabet chars** on and **Strict mode** off.
4. Confirm **Output value** is the decoded binary (for example the bytes for `hello`).

</details>

<details>
<summary>Decode with strict validation</summary>

Turn **Strict mode** on when you need to reject malformed Base64 instead of silently accepting odd lengths or padding.

1. Set **Input** to the Base64 string from the previous step.
2. Match **Alphabet** to the encoder.
3. Turn **Strict mode** on.
4. Confirm a well-formed string decodes to binary, or fix the Input if evaluation errors.

</details>
