# Data Type Storage Requirements

The following tables indicate the approximate data storage requirements for each data type.

## Numeric Data Types

| Data Type                                                                                      | Storage Requirement                   |
| ---------------------------------------------------------------------------------------------- | ------------------------------------- |
| [TINYINT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/tinyint)     | 1 byte                                |
| [SMALLINT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/smallint)   | 2 bytes                               |
| [MEDIUMINT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/mediumint) | 3 bytes                               |
| [INT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/int)             | 4 bytes                               |
| [BIGINT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/bigint)       | 8 bytes                               |
| [FLOAT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/float)(p)      | 4 bytes if p <= 24, otherwise 8 bytes |
| [DOUBLE](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/double)       | 8 bytes                               |
| [DECIMAL](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/decimal)     | See table below                       |
| [BIT](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/bit)(M)          | (M+7)/8 bytes                         |

Note that `MEDIUMINT` columns will require 4 bytes in memory (for example, in InnoDB buffer pool).

### Decimal

[Decimals](https://mariadb.com/docs/server/reference/data-types/numeric-data-types/decimal) are stored using a binary format, with the integer and the fraction stored separately. Each nine-digit multiple requires 4 bytes, followed by a number of bytes for whatever remains, as follows:

| Remaining digits | Storage Requirement |
| ---------------- | ------------------- |
| 0                | 0 bytes             |
| 1                | 1 byte              |
| 2                | 1 byte              |
| 3                | 2 bytes             |
| 4                | 2 bytes             |
| 5                | 3 bytes             |
| 6                | 3 bytes             |
| 7                | 4 bytes             |
| 8                | 4 bytes             |

## String Data Types

In the descriptions below, `M` is the declared column length (in characters or in bytes), while `len` is the actual length in bytes of the value.

| Data Type                                                                                                                                                                                        | Storage Requirement                                                                                        |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| [ENUM](https://mariadb.com/docs/server/reference/data-types/string-data-types/enum)                                                                                                              | 1 byte for up to 255 enum values, 2 bytes for 256 to 65,535 enum values                                    |
| [CHAR(M)](https://mariadb.com/docs/server/reference/data-types/string-data-types/char)                                                                                                           | M × w bytes, where w is the number of bytes required for the maximum-length character in the character set |
| [BINARY(M)](https://mariadb.com/docs/server/reference/data-types/string-data-types/binary)                                                                                                       | M bytes                                                                                                    |
| [VARCHAR(M)](https://mariadb.com/docs/server/reference/data-types/string-data-types/varchar), [VARBINARY(M)](https://mariadb.com/docs/server/reference/data-types/string-data-types/varbinary)   | len + 1 bytes if column is 0 – 255 bytes, len + 2 bytes if column may require more than 255 bytes          |
| [TINYBLOB](https://mariadb.com/docs/server/reference/data-types/string-data-types/tinyblob), [TINYTEXT](https://mariadb.com/docs/server/reference/data-types/string-data-types/tinytext)         | len + 1 bytes                                                                                              |
| [BLOB](https://mariadb.com/docs/server/reference/data-types/string-data-types/blob), [TEXT](https://mariadb.com/docs/server/reference/data-types/string-data-types/text)                         | len + 2 bytes                                                                                              |
| [MEDIUMBLOB](https://mariadb.com/docs/server/reference/data-types/string-data-types/mediumblob), [MEDIUMTEXT](https://mariadb.com/docs/server/reference/data-types/string-data-types/mediumtext) | len + 3 bytes                                                                                              |
| [LONGBLOB](https://mariadb.com/docs/server/reference/data-types/string-data-types/longblob), [LONGTEXT](https://mariadb.com/docs/server/reference/data-types/string-data-types/longtext)         | len + 4 bytes                                                                                              |
| [XMLTYPE](https://mariadb.com/docs/server/reference/data-types/string-data-types/xmltype)                                                                                                        | len + 4 bytes (same as LONGBLOB)                                                                           |
| [SET](https://mariadb.com/docs/server/reference/data-types/string-data-types/set-data-type)                                                                                                      | Given M members of the set, (M+7)/8 bytes, rounded up to 1, 2, 3, 4, or 8 bytes                            |
| [INET6](https://mariadb.com/docs/server/reference/data-types/string-data-types/inet6)                                                                                                            | 16 bytes                                                                                                   |
| [UUID](https://mariadb.com/docs/server/reference/data-types/string-data-types/uuid-data-type)                                                                                                    | 16 bytes                                                                                                   |

**Note**: Introduced in MariaDB 12.3, the `XMLTYPE` data type has a maximum storage capacity of 4GB, similar to `LONGBLOB`*.*

In some [character sets](https://mariadb.com/docs/server/reference/data-types/string-data-types/character-sets), not all characters use the same number of bytes. utf8 encodes characters with one to three bytes per character, while `utf8mb4` requires one to four bytes per character.

When using field the `COMPRESSED` attribute, 1 byte is reserved for metadata. For example, `VARCHAR(255)` will use +2 bytes instead of +1.

### Examples

Assuming a single-byte character-set:

| Value | CHAR(2) | Storage Required | VARCHAR(2) | Storage Required |
| ----- | ------- | ---------------- | ---------- | ---------------- |
| ''    | ' '     | 2 bytes          | ''         | 1 byte           |
| '1'   | '1 '    | 2 bytes          | '1'        | 2 bytes          |
| '12'  | '12'    | 2 bytes          | '12'       | 3 bytes          |

## Date and Time Data Types

| Data Type                                                                                            | Storage Requirement |
| ---------------------------------------------------------------------------------------------------- | ------------------- |
| [DATE](https://mariadb.com/docs/server/reference/data-types/date-and-time-data-types/date)           | 3 bytes             |
| [TIME](https://mariadb.com/docs/server/reference/data-types/date-and-time-data-types/time)           | 3 bytes             |
| [DATETIME](https://mariadb.com/docs/server/reference/data-types/date-and-time-data-types/datetime)   | 8 bytes             |
| [TIMESTAMP](https://mariadb.com/docs/server/reference/data-types/date-and-time-data-types/timestamp) | 4 bytes             |
| [YEAR](https://mariadb.com/docs/server/reference/data-types/date-and-time-data-types/year-data-type) | 1 byte              |

### Microseconds

MariaDB defaults to the MySQL format (by means of the [mysql56\_temporal\_format](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#mysql56_temporal_format) variable). Microseconds have the following additional storage requirements:

| Precision | Storage Requirement |
| --------- | ------------------- |
| 0         | 0 bytes             |
| 1,2       | 1 byte              |
| 3,4       | 2 bytes             |
| 5,6       | 3 bytes             |

## NULL Values

For the InnoDB [COMPACT](https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-row-formats/innodb-compact-row-format), [DYNAMIC](https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-row-formats/innodb-dynamic-row-format) and [COMPRESSED](https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-row-formats/innodb-compressed-row-format) row formats, a number of bytes will be allocated in the record header for the nullable fields. If there are between 1 and 8 nullable fields, 1 such byte will be allocated. In the record payload area, no space will be reserved for values that are `NULL`.

For the [InnoDB REDUNDANT row format](https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-row-formats/innodb-redundant-row-format), the overhead is 1 bit in the record header (as a part of the 1-byte or 2-byte "end of field" pointer). In that format, a `NULL` fixed-length field will consume the same amount of space as any `NOT NULL` value in the record payload area. The motivation is that it is possible to update in place between `NOT NULL` and `NULL` values.

In other formats, `NULL` values usually require 1 bit in the data file, 1 byte in the index file.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/data-types/data-type-storage-requirements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
