String length calculator (characters and bytes)

A string's length depends on what you count: user-visible characters, Unicode code points, UTF-16 code units (what JavaScript's .length reports) or UTF-8 bytes (what storage and byte limits count), while SMS counts its own 7-bit or 16-bit units. Paste text to see all of them side by side.

Counted exactly as typed: spaces, line breaks and invisible characters all count.

Characters

11

14 code points · 15 UTF-16 units (.length) · 29 UTF-8 bytes

Characters you see
11grapheme clusters (Intl.Segmenter)
Characters, excluding spaces
9spaces, tabs and line breaks left out
Unicode code points
14[...text].length in JavaScript; len() in Python
UTF-16 code units
15JavaScript's .length
UTF-8 bytes
29a UTF-8 file or utf8mb4 column; len() in Go
UTF-16 bytes
302 per code unit, without a byte order mark
Words
2word boundaries from Intl.Segmenter
Lines
1a line break at the very end doesn't start a new line
SMS encoding
UCS-2 (16-bit)“👋”, “न”, “म”, “स”, “्” and more aren't in the GSM 7-bit alphabet
SMS segments
115 of 70 16-bit units
Characters in your text that aren't plain ASCII, and what each one costs
CharacterTimesCode pointsUTF-16 unitsUTF-8 bytes
👋1U+1F44B24
न1U+092813
म1U+092E13
स्ते1U+0938 U+094D U+0924 U+0947412
  • 11 visible characters are made of 14 code points: an emoji with a skin tone, a flag, or a letter with a combining mark or vowel sign is one character on screen but several code points.
  • 1 code point above U+FFFF takes two UTF-16 code units each (a surrogate pair), which is why .length is 15 and not 14.

How is the length of a string counted?

A string has several lengths, depending on the unit. The characters you see are grapheme clusters, defined by Unicode's text segmentation rules (UAX #29) and counted here with the browser's Intl.Segmenter. Underneath, each one is one or more Unicode code points: an accented letter can be one code point or two, and the three-person family emoji is five code points (three people and two zero-width joiners) shown as one picture.

Code points are then stored as code units. JavaScript strings are UTF-16, so .length counts 16-bit units, and a code point above U+FFFF, such as the waving hand emoji U+1F44B, takes two of them, a surrogate pair. UTF-8, the encoding TextEncoder produces and MySQL's utf8mb4 stores, uses 1 to 4 bytes per code point (RFC 3629): 1 for ASCII, 2 for é, 3 for ₹ and for Hindi and Tamil letters, and 4 for anything above U+FFFF.

Words come from the same segmenter's word boundaries, which also work for languages written without spaces; punctuation and emoji don't count as words. Lines are counted from line breaks, with a break at the very end not starting a new line.

SMS uses its own count. 3GPP TS 23.038 says a message in the GSM 7-bit default alphabet can hold up to 160 characters, and one in UCS2 up to 70; a message with even one character outside that alphabet, such as ₹, an emoji or a Hindi letter, needs UCS2 instead. UCS2 stops at U+FFFF, so this page counts a character above it, such as an emoji, as two 16-bit units, the way UTF-16 writes it; check with your SMS provider for those. The extension table characters € [ ] { } \ ^ ~ | each take two of the 160. TS 23.040 sets 153 and 67 per part when a message is split, because each part carries a header for reassembly.

Segmentation follows the Unicode version of the browser. Unicode 15.1 added a rule (GB9c) that keeps Devanagari conjuncts such as स्ते together, so नमस्ते is 3 characters on current systems and 4 with older Unicode data. TS 23.038 also defines national language tables for Hindi, Tamil and other languages, but says locking-shift encoding isn't intended to be used until a national regulator asks for it, so this page counts with the default alphabet.

characters you see  →  Intl.Segmenter(granularity: "grapheme")
code points         →  [...text].length
UTF-16 code units   →  text.length
UTF-8 bytes         →  new TextEncoder().encode(text).length
SMS: GSM 7-bit 160, or 153 per part · UCS-2 70, or 67 per part

How long are emoji, accented letters and Indian scripts?

Example strings counted four ways, with the SMS encoding they need (grapheme counts from the Unicode data of the page's server)
TextCharacters you seeCode pointsUTF-16 units (.length)UTF-8 bytesSMS
A1111GSM 7-bit, 1 septet
é (one code point, U+00E9)1112GSM 7-bit, 1 septet
é (e + combining U+0301)1223UCS-2, 2 units
₹1113UCS-2, 1 unit
€1113GSM 7-bit, 2 septets
👋1124UCS-2, 2 units
👋🏽 (with a skin tone)1248UCS-2, 4 units
👨‍👩‍👧 (family, joined)15818UCS-2, 8 units
🇮🇳 (flag)1248UCS-2, 4 units
नमस्ते (Hindi)36618UCS-2, 6 units
வணக்கம் (Tamil)57721UCS-2, 7 units
Hello 👋 नमस्ते11141529UCS-2, 15 units

How to count the characters and bytes in a string

  1. 1
    Paste the textType or paste up to 200,000 characters. It is counted in your browser as you type, and nothing is sent anywhere.
  2. 2
    Pick the count you needUse the characters you see for a visible limit, code points or UTF-16 units for code, and UTF-8 bytes for storage or an API's byte limit.
  3. 3
    Check the SMS costSee whether the text fits the GSM 7-bit alphabet or needs UCS-2, and how many segments it takes.
  4. 4
    Find the costly charactersThe table lists every character that isn't plain ASCII with its code points, UTF-16 units and UTF-8 bytes.

Frequently asked questions

Why does JavaScript's .length count one emoji as 2?
Because .length counts UTF-16 code units, not characters. An emoji such as the waving hand, U+1F44B, is above U+FFFF, so it takes two units, a surrogate pair. Sequences count more: the waving hand with a skin tone is 4 units, and a family emoji made of three people joined by zero-width joiners is 8. Use [...text].length for code points or Intl.Segmenter for what you see.
Does MySQL VARCHAR(255) count characters or bytes?
Characters. MySQL's manual says the length of CHAR and VARCHAR is the maximum number of characters, so VARCHAR(255) holds up to 255 characters, however many bytes each one needs. Bytes still matter: utf8mb4 needs up to four bytes per character, and the 65,535-byte maximum row size is shared by all the columns of a table.
How many characters fit in one SMS?
160 if every character is in the GSM 7-bit alphabet, or 70 if any one isn't, since the message then needs UCS2, and 3GPP TS 23.038 allows 140 octets, 70 UCS2 characters. A longer message is split into parts of 153 or 67 characters, since each part carries a header for reassembly (TS 23.040). € [ ] { } \ ^ ~ and | each count as two in GSM 7-bit.
How many bytes does a Hindi or Tamil letter take in UTF-8?
Three per code point. Devanagari and Tamil code points are between U+0800 and U+FFFF, which UTF-8 writes in 3 bytes (RFC 3629). A visible letter often has more than one code point: नमस्ते is 6 code points, so 18 bytes, though it shows as 3 or 4 characters. In UTF-16 the same word is 12 bytes.
Why can two strings that look identical have different lengths?
Because Unicode has more than one way to write some characters. é can be the single code point U+00E9, or e followed by the combining accent U+0301: both show as one character, but the second is 2 code points and 3 UTF-8 bytes instead of 2. Normalizing both to NFC with text.normalize("NFC") makes them equal.

Sources

Related tools

See all 73 free tools

Need a custom dev tool for your team?

We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.

Built by CountryDevs · No signup · No ads · We count visits, never what you enter