String Length, UTF-8 Byte Counter & Regex Tester

Count characters, code points, UTF-8, UTF-16 and UTF-32 bytes in any text, including emoji, and test a regular expression against it.

Updated · Free · Runs in your browser

g, i, m, s, u or y

Characters (as displayed) —
UTF-8 size —
Unicode code points —
UTF-16 —
UTF-32 —
Words and lines —
Regex matches —
Length limits —
    Was this calculator helpful?

    The formula

    UTF-8 bytes per code point: 1 (U+0000–007F), 2 (U+0080–07FF), 3 (U+0800–FFFF), 4 (U+10000 and above)
    UTF-16: 2 bytes per code unit; characters above U+FFFF use a surrogate pair (2 units)
    UTF-32: 4 bytes per code point
    Graphemes (visible characters) can combine several code points, e.g. family emoji 👨‍👩‍👧 = 5 code points

    Worked example

    1. "Café ☕ costs €3.50": é is 2 bytes in UTF-8, ☕ and € are 3 bytes each, and the other 15 characters are 1 byte, so 18 visible characters take 23 bytes.
    2. The family emoji 👨‍👩‍👧 looks like one character but is 3 people joined by 2 zero-width joiners: 5 code points, 8 UTF-16 units and 18 UTF-8 bytes.
    3. The pattern #[A-Z]-\d+ matches #A-1042 and #B-77.

    Why string length is complicated

    "How long is this text?" has several correct answers. A user counts visible characters, a database column or API might count bytes, JavaScript counts UTF-16 code units, and Unicode itself counts code points. For plain English text these are all the same, but accented letters, non-Latin scripts and especially emoji make them differ. Getting it wrong causes truncated text, broken emoji, failed database inserts and messages that are split unexpectedly. This tool shows every measure side by side.

    UTF-8 bytes

    UTF-8 is the dominant text encoding on the web, used by over 98% of websites. It's variable-width: ASCII characters take one byte, most European accented letters and Greek, Cyrillic, Hebrew and Arabic characters take two, most Chinese, Japanese and Korean characters and symbols such as € take three, and emoji and rare characters take four. Byte length matters for storage limits, such as MySQL's index key limits, HTTP header sizes, URL lengths, network payload costs and protocols that specify sizes in bytes.

    Code points, UTF-16 and JavaScript

    A code point is a single Unicode value, written as U+ followed by hex digits. JavaScript, Java and C# store strings in UTF-16, so their length property counts 16-bit code units: characters outside the Basic Multilingual Plane, including most emoji, need two units, a surrogate pair. That's why "😀".length is 2 in JavaScript. Use [...str].length or Array.from(str).length to count code points, and Intl.Segmenter to count user-perceived characters, which the calculator uses when your browser supports it.

    Graphemes and emoji

    What looks like one character can be built from several code points. Accented letters can be a base letter plus a combining accent, flags are pairs of regional indicator symbols, skin-tone emoji add a modifier, and family and profession emoji join several emoji with invisible zero-width joiners. Cutting a string in the middle of one of these sequences produces broken symbols. For user-facing limits such as usernames and post lengths, count graphemes; for storage, count bytes.

    Testing regular expressions

    Enter a JavaScript regular expression and optional flags to see how many matches it finds and what they are. The global flag is always added so every match is found. Add i for case-insensitive matching, m for multiline anchors, s to let . match newlines and u for full Unicode support, which you need for patterns such as \p{L} for any letter. Remember that without the u flag, . and character classes treat emoji as two separate code units. Regular expressions run locally in your browser.

    Database column limits

    Databases measure limits differently. MySQL's VARCHAR(255) with the utf8mb4 character set counts characters, but each can use up to 4 bytes, and index keys are limited in bytes. PostgreSQL's varchar(n) counts characters. SQL Server's nvarchar counts UTF-16 code units, so an emoji uses two. Always test limits with emoji and non-Latin text, not just English.

    Length limits to watch

    Common limits include 160 characters for an SMS in the GSM-7 alphabet, dropping to 70 when any character outside it, such as an emoji, forces UCS-2 encoding; 280 characters for posts on X (Twitter), where most CJK characters and emoji count double; around 50–60 characters before search engines truncate page titles; and 255 bytes for many file names. For SEO text, use our keyword density checker; for encoded sizes, the Base64 calculator; and for typing tests, the typing speed calculator.

    Frequently asked questions

    How many bytes is a character in UTF-8?
    Between 1 and 4. ASCII letters and digits take 1 byte, accented Latin letters 2, most Asian characters and symbols such as € 3, and emoji 4.
    Why does JavaScript say an emoji has length 2?
    JavaScript strings use UTF-16, and emoji outside the Basic Multilingual Plane need a surrogate pair of two code units. Use [...text].length to count code points.
    How do I count characters the way users see them?
    Count grapheme clusters, for example with Intl.Segmenter in JavaScript. This treats combined emoji and accented letters as single characters.
    Does an emoji count as one character in an SMS?
    No. Any emoji switches the message to UCS-2 encoding, where each emoji uses two of the 70 available characters per message part.
    Is this regex tester the same as in my language?
    It uses JavaScript's regular expression engine. Most syntax is shared with Python, Java and PCRE, but features such as lookbehind and named groups can differ slightly.

    ↑↓ to navigate · Enter to open