Works on this device
Varchar Byte Length Calculator
See how many bytes a text takes in UTF-8, UTF-16 and a single-byte code page, and whether it fits a VARCHAR(n) column. Engines count n in different ways: in characters, in bytes or in byte-pairs. The check is done in your browser; no database is used.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Check.
Your result
How it was worked out
How to use this calculator
- Type or paste the text. The counts update as you type.
- Choose the column, such as MySQL VARCHAR(n) CHARACTER SET utf8mb4 or SQL Server nvarchar(n), and type n.
- Read whether it fits. If it does not, the result shows the longest start of the text that fits. The table checks the same text in every column kind.
- To check a list, choose Check many values, one on each line. To see the most bytes a column can take, choose Most bytes a VARCHAR(n) column can need.
What n counts in each engine
| Column | n counts | Largest n | Length bytes stored |
|---|---|---|---|
| PostgreSQL 16 and 17 varchar(n) | characters | 10,485,760 | 1 up to 126 bytes, else 4 |
| MySQL 8.0 and 8.4 VARCHAR(n), utf8mb4 | characters (up to 4 bytes each) | 16,383 | 1 when n × 4 ≤ 255, else 2 |
| MySQL VARCHAR(n), utf8mb3 | characters (up to 3 bytes; no emoji) | 21,844 | 1 when n × 3 ≤ 255, else 2 |
| MySQL VARCHAR(n), latin1 | characters (1 byte each) | 65,533 | 1 when n ≤ 255, else 2 |
| SQL Server 2019 and 2022 varchar(n) | bytes | 8,000 (or max) | 2 |
| SQL Server nvarchar(n) | byte-pairs (UTF-16 code units) | 4,000 (or max) | 2 |
| Oracle Database 19c and 23ai VARCHAR2(n BYTE) | bytes | 4,000 (32,767 extended) | 1 up to 250 bytes, else 3 |
| Oracle VARCHAR2(n CHAR) | characters, and at most 4,000 bytes | 4,000 | 1 up to 250 bytes, else 3 |
| SQLite 3.39 and later | nothing: n is not checked | 1,000,000,000 bytes by default | a small record header |
Bytes of one character
- UTF-8: 1 byte for A to Z, digits and plain punctuation; 2 bytes for most accented Latin letters (é, ł); 3 bytes for most other characters (€, 東); 4 bytes above U+FFFF (most emoji).
- UTF-16: 2 bytes for characters up to U+FFFF and 4 bytes (two code units) above it. SQL Server nvarchar(n) counts these code units, so an emoji uses 2 of n.
- Windows-1252 (MySQL latin1, SQL Server code page 1252): 1 byte for each of its 251 characters. Other characters, such as 東 or an emoji, cannot be stored as typed.
- A character as a reader sees it can be several code points: an accent typed as a separate mark, or an emoji joined from parts. Engines count code points.
Worked example
The text Crème brûlée, 5 € 🍮 has 19 characters. In UTF-8 it is 27 bytes: 14 plain characters of 1 byte, è, û and é with 2 bytes each, € with 3 and the emoji with 4. In UTF-16 it is 20 code units (40 bytes).
In MySQL VARCHAR(20) with utf8mb4 it uses 19 of 20 characters and fits, and is stored in 28 bytes with its length byte. In SQL Server varchar(20) with a UTF-8 collation it needs 27 bytes and does not fit. In a latin1 or code page 1252 column the emoji cannot be stored.
In MySQL VARCHAR(16) it does not fit: 19 characters is more than 16. The longest start that fits is the first 16 characters, Crème brûlée, 5 (with the space at its end).
Other tools for the same subject
- To change a column type or CAST a value between engines, use the SQL Data Type Converter.
- To see the bytes themselves in UTF-8, UTF-16 and other encodings, use the Character Encoding Converter.
- To count words and characters of a long text, use the Word Counter.
Limits you should know
- The text is counted as you typed it. Engines that normalise text or trim spaces at the end can store a different length.
- MySQL keeps a whole row within 65,535 bytes, so the largest n is smaller when the table has other columns. Index keys have their own, smaller limits.
- SQL Server varchar with a code page 1252 collation may change a character it cannot hold into a near one or a question mark; here such a text counts as one the column cannot hold.
- Compression and storage outside the row are not counted.