TTKTheTextKit

Text Byte Size Calculator

Paste a text and see how many bytes it takes in UTF-8, UTF-16 and UTF-32, along with the number of characters, the UTF-16 length that JavaScript reports and the size in ISO-8859-1. A breakdown shows how many characters take 1, 2, 3 and 4 bytes in UTF-8. Enter a limit in bytes to see how much room is left, or how much is over, and trim the text to fit without cutting a character in half. Everything runs in your browser.

UTF-8 bytes
15 bytes
The usual encoding of files and the web
Characters
9
10 UTF-16 units, as JavaScript counts them
UTF-16 bytes
20 bytes
Two bytes a unit
UTF-32 bytes
36 bytes
Four bytes a character
ISO-8859-1 (Latin-1) bytes
Does not fit
A character is above U+00FF
UTF-8 bytes per character
6 x 1, 1 x 2, 1 x 3, 1 x 4
Characters of 1, 2, 3 and 4 bytes

A computer stores text as bytes, and how many depends on the encoding. UTF-8 uses 1 byte for the characters U+0000 to U+007F, which are the same as ASCII, 2 bytes up to U+07FF, 3 bytes up to U+FFFF and 4 bytes above that, so an accented letter takes 2, a euro sign takes 3 and an emoji takes 4. UTF-16 uses 2 bytes for most characters and 4 for those above U+FFFF, which JavaScript counts as 2 in its length. UTF-32 uses 4 bytes for every character. A byte order mark, if the file has one, adds 3 bytes in UTF-8, 2 in UTF-16 and 4 in UTF-32. Limits such as a database column, an SMS part or an API field are often in bytes and not in characters, so a text of 100 characters can be 100 to 400 bytes. The trim button cuts after the last whole character that fits, never in the middle of one. It counts code points, so a letter with a separate accent, or an emoji made of several parts, counts as more than one character. Everything runs in your browser.

Related Tools

[6 suggestions]

About the Text Byte Size Calculator

A computer stores text as bytes, and how many depends on the encoding. UTF-8, the usual encoding of files and the web, uses 1 byte for the characters U+0000 to U+007F, which are the same as ASCII, 2 bytes up to U+07FF, 3 bytes up to U+FFFF and 4 bytes above that, so an accented letter such as e with an acute accent takes 2 bytes, the euro sign takes 3 and an emoji takes 4. UTF-16 uses 2 bytes for most characters and 4 for those above U+FFFF, which is why JavaScript reports the length of an emoji as 2, and UTF-32 uses 4 bytes for every character. ISO-8859-1, also called Latin-1, uses one byte a character but only covers U+0000 to U+00FF, so the tool says when a text does not fit. If a file starts with a byte order mark, it adds 3 bytes in UTF-8, 2 in UTF-16 and 4 in UTF-32, and a checkbox counts it. Limits such as a database column, an SMS part, an HTTP header or an API field are often in bytes and not in characters, so a text of 100 characters can be 100 to 400 bytes, and the tool shows both so you can see which limit you are close to. When you enter a limit, it tells you how many bytes are left or how many are over, and a button trims the text to the longest start that fits, always after a whole character. A lone surrogate, which is not a valid character, is counted as the 3 byte replacement character that encoders write. It counts code points, so a letter with a separate combining accent, or an emoji built from several parts such as a family, counts as more than one character.

How many bytes is my text in UTF-8?▾

Paste it in. Each character takes 1 byte if it is ASCII, 2 bytes for most Latin accents, Greek and Cyrillic, 3 for most other scripts and the euro sign, and 4 for emoji. The tool adds them up for you.

Why is the byte count bigger than the character count?▾

Because only the first 128 characters take one byte in UTF-8. Accented letters take 2, many symbols and scripts take 3, and emoji take 4, so a short text of such characters can have several times as many bytes as characters.

How do I fit a text into a byte limit?▾

Enter the limit in bytes. The tool shows how many bytes are left or over, and the Trim button cuts the text after the last whole character that fits, so it never leaves half a character.

What is the difference between UTF-8, UTF-16 and UTF-32?▾

UTF-8 uses 1 to 4 bytes a character and is the same as ASCII for the first 128. UTF-16 uses 2 or 4 bytes. UTF-32 always uses 4. All three can represent every Unicode character.

Does a byte order mark count?▾

Only if the file has one. A UTF-8 byte order mark adds 3 bytes, UTF-16 adds 2 and UTF-32 adds 4. It is optional in UTF-8, so tick the box only when your file starts with it.