> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Bytes

A value that represents the bytes used ubiquitously in computer hardware.

Bytes represent raw binary data. While most data in SurrealDB is stored as strings or structured values, bytes are useful when working with encoded data such as hashes, binary identifiers, or compact representations.

A `bytes` value is stored inside its record, so it is read and written together with the rest of the record's fields. For whole files such as images or documents, the experimental [files feature](/docs/learn/schema-management/files/working-with-files.md) stores the content in a [bucket](/docs/learn/schema-management/files/buckets.md) held in memory, on disk or in cloud object storage. A record field then holds a file pointer such as `f"images:/cat.jpg"`, and calling `.get()` on the pointer returns the file's content as bytes.

## Casting from strings

Bytes can be created by casting from a string, and are displayed using hexadecimal encoding.

```surql
<bytes>"I am some bytes";
```

```surql title="Output"
b"4920616D20736F6D65206279746573"
```

## Conversion from other types

_(since v2.3.0)_

Conversions can be performed between bytes, strings, and arrays.

```surql
-- array<int> to bytes to string
<string><bytes>[99, 101, 108, 108, 97, 114, 32, 100, 111, 111, 114];
-- string to bytes to array<int>
<array><bytes>"Hobbits";
```

```surql title="Output"
-------- Query --------

'cellar door'

-------- Query --------

[72, 111, 98, 98, 105, 116, 115]
```

## Byte strings

_(since v3.0.0)_

A string preceded by a `b` prefix can be turned into bytes as long as the string represents a hexadecimal value.

```surql
b"486F6262697473";

<string>b"486F6262697473";

<string>b"This won't work though";
```

```surql title="Output"
-------- Query --------

b"486F6262697473";

-------- Query --------

'Hobbits'

-------- Query --------

"There was a problem with the database: Parse error: Unexpected
  character `T` expected hexidecimal digit
 --> [1:11]
  |
1 | <string>b\"This won't work though\";
  |           ^ 
"
```

## Learn more about this topic

- [4: Data types](https://surrealdb.com/learn/schemas/page-04#bytes) (SurrealDB University, section "Bytes")
