# To Base64

Converts the input to Base64. Use it when you need to send binary data through text-only channels (APIs, email, logs) or
when a downstream step expects a Base64 string. Supports multiple alphabets ([RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648)
standard and URL-safe, plus other common variants). To Base64 lives in the **Data format** category of the `fx` menu.

To reverse the encoding, use [From Base64](../from-base64/).

## Parameters

| Parameter | Type   | Required | Default                             | Description                                                                                                                                                                                                                                        |
| --------- | ------ | -------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Input     | binary | yes      | —                                   | Raw bytes to encode. Previous step output that provides binary data, or binary-capable input.                                                                                                                                                      |
| Alphabet  | string | yes      | `Standard (RFC 4648): A-Za-z0-9+/=` | Defines the 64 Base64 sextet symbols. Use a preset (RFC 4648, URL-safe, Filename safe, and others) or a matching custom alphabet. Encoding and decoding must use the same alphabet. See [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648). |

`Input` is the primary value (previous step output or a literal). **Alphabet** is an editable preset on the function
card.

## Returned value

| Type     | Description                                    |
| -------- | ---------------------------------------------- |
| `string` | The Base64-encoded ASCII string for the input. |

## Limitations

- Input must be binary (`ArrayBuffer`). Non-binary input raises `toBase64: functionInput must be an ArrayBuffer`.
- Alphabet must be a string. Use the same alphabet later with [From Base64](../from-base64/).
- URL-safe alphabets omit or replace `+`, `/`, and padding differently — pick the preset that matches the consumer.

## Examples

<details>
<summary>Encode with the standard alphabet</summary>

Encode binary or text-as-bytes into a standard Base64 string — the most common Base64 use in a flow.

1. Set **Input** to the bytes or text from the previous step.
2. Leave **Alphabet** on `Standard (RFC 4648): A-Za-z0-9+/=`.
3. Confirm **Output value** is a Base64 string (for example `hello` becomes `aGVsbG8=`).

</details>

<details>
<summary>Encode with the URL-safe alphabet</summary>

Use the URL-safe alphabet when the Base64 string will appear in a URL or filename and you must avoid `+` and `/`.

1. Set **Input** to the bytes to encode.
2. Set **Alphabet** to `URL safe (RFC 4648 §5): A-Za-z0-9-_`.
3. Confirm **Output value** uses `-` and `_` instead of `+` and `/` where those sextets appear.

</details>
