Characters are not bytes
A character is a letter or symbol. A byte is a unit of storage. In plain English text every character takes one byte, but accented letters take two, most Asian scripts take three and emoji take four. A text of 100 characters can therefore be anywhere from 100 to 400 bytes. Limits for files, database columns, API fields and SMS parts are often set in bytes, so the character count alone is not enough.
Bytes by encoding
| Encoding | Bytes per character | Used for |
|---|---|---|
| UTF-8 | 1 to 4 | The web, files, APIs and most databases |
| UTF-16 | 2 or 4 | JavaScript, Java, Windows and .NET strings in memory |
| UTF-32 | 4 | Fixed-width storage, some internal use |
| Latin-1 (ISO-8859-1) | 1 | Older systems. It cannot store characters above U+00FF. |
What this tool shows
- The byte count in each encoding, and the size in KB.
- A table of how many characters take 1, 2, 3 or 4 bytes in UTF-8, with the bytes they use.
- The number of characters that cannot be stored in Latin-1.
- A limit check: type a limit in bytes and see whether the text fits, and by how much.
Options
- Add a byte order mark: adds 3 bytes to UTF-8, 2 to UTF-16 and 4 to UTF-32, for files saved with a BOM.
- Count line breaks as two bytes: counts every line break as the Windows pair of carriage return and line feed.
Counting bytes in code
// JavaScript
new TextEncoder().encode(text).length
# Python
len(text.encode("utf-8"))
// PHP (strlen counts bytes, mb_strlen counts characters)
strlen($text);
Related tools
For plain character counts use the character counter with spaces. To look at the bytes of a string as Base64, see text to Base64. The character count guide explains characters, code points and bytes in more detail.