# encode

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: encode
latest-operator-version: v26.2.4
latest-console-tag: v3.12.0
latest-connect-version: 4.113.1
latest-redpanda-tag: v26.2.4
docname: sql/sql-functions/string-functions/encode
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/string-functions/encode.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/string-functions/encode.adoc
description: The `encode()` function encodes binary data into a text representation using a specified format.
page-topic-type: reference
page-git-created-date: "2026-09-08"
page-git-modified-date: "2026-09-08"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/encode.md -->

The `encode()` function encodes binary ([`bytea`](https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-data-types/bytea/)) data into a text representation using a specified format. See also [`decode()`](https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/decode/) to reverse this operation.

## [](#syntax)Syntax

The syntax of the `encode()` function is:

```sql
ENCODE(data, format)
```

The `encode()` function requires two arguments:

-   `data`: The `bytea` value to encode.

-   `format`: The encoding format to use. Supported values are `hex`, `base64`, and `escape`.


## [](#examples)Examples

### [](#encode-binary-data-as-hex)Encode binary data as hex

This example encodes a `bytea` value as a hexadecimal string:

```sql
SELECT ENCODE('\xdeadbeef'::bytea, 'hex');
```

```sql
+------------+
| encode     |
+------------+
| deadbeef   |
+------------+
```

### [](#encode-binary-data-as-base64)Encode binary data as base64

This example encodes a `bytea` value as a base64 string:

```sql
SELECT ENCODE('\x48656c6c6f'::bytea, 'base64');
```

```sql
+------------+
| encode     |
+------------+
| SGVsbG8=   |
+------------+
```