CalcSeed

String Length Calculator

Enter text to count its characters, bytes, words and lines.

=
Quick answer: with the default inputs (Hello, world!), the characters is 13. At these inputs: uTF-8 bytes = 13, words = 2. Change any input to update the result.
Characters
—

What the four numbers mean

Paste text and the tool reports four counts: characters, UTF-8 bytes, words and lines. For the default "Hello, world!" the results are 13 characters, 13 bytes, 2 words and 1 line. Characters and bytes are equal here only because the sample is pure ASCII; the two measures diverge the moment an accented letter, a CJK character or an emoji enters the text, and that divergence is exactly what this calculator makes visible.

bytes=n1+2n2+3n3+4n4bytes = n1 + 2*n2 + 3*n3 + 4*n4

Characters versus bytes: the encoding rules

UTF-8 is a variable-length encoding. Characters at or below code point U+007F — all of ASCII — take 1 byte. Characters up to U+07FF, which covers Latin letters with accents, Greek and Cyrillic, take 2 bytes. Characters up to U+FFFF, which covers Arabic, CJK ideographs and most scripts, take 3 bytes. Everything rarer — emoji, historical scripts, mathematical symbols — takes 4 bytes. The byte count is the weighted sum of those four groups.

CharacterCode pointUTF-16 unitsUTF-8 bytes
AU+004111
é (acute e)U+00E912
CJK ideographU+4E2D13
emoji (most)U+1F600 range24
spaceU+002011

Reading the emoji row

The UTF-16 column explains another surprise: JavaScript’s .length counts UTF-16 code units, so a 4-byte emoji registers as 2 characters. A string holding 10 emoji reports a length of 20 while its UTF-8 size is 40 bytes — one glyph, two code units, four bytes.

Worked example at the default input

The default text is 13 characters: Hello (5) + comma (1) + space (1) + world (5) + punctuation (1). Every one of them is ASCII below U+0080, so the byte count is also exactly 13. The word counter sees two runs of non-whitespace separated by the space — Hello, and world — giving 2 words, and with no newline in the text, 1 line. Punctuation stays attached to its word rather than counting separately.

Swap one character to watch the numbers split. Replace the H with é and the character count stays 13 while the byte count rises to 14. Add a single emoji and the length grows by 2 code units while bytes grow by 4. This is why a 13-character name can still break a 10-byte database column, and why SMS switches from 160 characters to 70 as soon as one emoji appears.

How words and lines are counted

A word is any maximal run of non-whitespace characters, where whitespace means space, tab, line feed and carriage return. The scan walks the string once, starting a new word whenever it leaves whitespace. Consecutive separators count as one boundary: two spaces between words do not create an empty word, and a document that begins or ends with whitespace gains no phantom words.

Lines are counted by line-feed characters, plus one for a final line without a trailing newline. A 5-line file joined by 4 newlines counts 5 lines; the same content with a trailing newline counts 6, because the empty string after the last newline is technically a line. That off-by-one is the most common complaint about line counts anywhere in computing.

Where each count is enforced

  • Character counts govern input fields, tweet-length posts and API string-length limits
  • Byte counts govern database columns (VARCHAR(n) is bytes in some engines), HTTP payload budgets and wire protocols
  • Word counts govern abstract limits, translation quotes and search-engine content guidance
  • Line counts govern diff sizes, log parsers and file-format row limits

The character/byte gap has real consequences. A VARCHAR(255) column in a utf8mb4 MySQL table holds 255 characters, but a UTF-8 index entry can span up to 1,020 bytes. A 100-character Japanese string is about 300 bytes in UTF-8. When a backend rejects a payload that "looked short enough", the byte count was the binding constraint.

Common counting mistakes

  • Assuming characters equal bytes — true only for pure ASCII, as the 13/13 default shows, and false the instant accents appear
  • Expecting an emoji to count as 1 character — it is 2 UTF-16 code units and 4 UTF-8 bytes
  • Pasting with a trailing newline and seeing the line count rise by 1
  • Confusing grapheme clusters with code units — a letter plus combining accent is 2 code units but reads as 1 character
  • Treating non-breaking space as whitespace — it is not in the space/tab/newline set, so it glues words together

Choosing the right number for a limit

Match the count to whatever enforces your limit. Browser maxlength and most APIs enforce UTF-16 code units, so use the character number. Database columns and network budgets enforce bytes, so use the byte number. For readability limits such as abstracts, use words. When you also need letter, digit and sentence tallies, the Character Counter breaks the same text down further, and the Unicode Codepoint Calculator shows the code point behind any single character.

Frequently asked questions

How many characters and bytes is "Hello, world!"?

13 of each. Every character in the default text is ASCII, which takes exactly 1 UTF-8 byte, so the two counts match. Add one accented letter or emoji and they diverge immediately.

Why do emoji count as two characters?

JavaScript strings are UTF-16, and emoji outside the basic plane are stored as a surrogate pair of 2 code units. Their UTF-8 size is 4 bytes, so one emoji adds 2 to the character count and 4 to the byte count.

How many bytes is a Chinese character?

3 in UTF-8 for most CJK ideographs, which sit in the U+4E00–U+9FFF range. A 100-character Chinese string therefore occupies about 300 bytes even though its character count is 100.

Is the byte count the same as the file size?

Nearly. UTF-8 bytes equal the file size when the file contains only that text with no byte order mark and no trailing newline. A saved file with a BOM adds 3 bytes and a trailing newline adds 1.

How are words counted?

Any maximal run of non-whitespace characters counts as one word, with space, tab, line feed and carriage return acting as separators. Punctuation attaches to its word, so "Hello," counts as a single 6-character word.

Why does my line count show one extra line?

A trailing newline at the end of the text creates an empty final line, which is counted. A 5-line file ending with a newline reports 6 lines; delete the trailing newline and it reports 5.

What is the difference between characters and code points?

For most text, none — each code point is one character. Differences appear with combining marks, where a letter plus its accent is 2 code points but 1 visible character, and with emoji composed of several joined parts.

Which count should I use for a form limit?

Use the character count for browser maxlength and most API limits, which enforce UTF-16 code units. Use the byte count for database columns and payload budgets, and the word count for prose limits such as abstracts.

Why is my count different from another tool?

Tools disagree on three things: whether to count code units or grapheme clusters, whether a trailing newline counts as a line, and whether non-breaking space counts as whitespace. This tool counts UTF-16 code units, includes trailing newlines as lines, and treats only space, tab, line feed and carriage return as whitespace.

Method and sources

Calculation basis

Conversions and formats follow the relevant IETF RFCs and IEEE standards, including RFC 4648 for Base64 and RFC 791 for IPv4 addressing.

Last updated: November 17, 2026
Formula & data sources
  • UTF-8 encoding rules as defined by the Unicode Standard.

Cite this page

Reference formats
APA 7CalcSeed. (2026, November 17). String Length Calculator. https://calcseed.com/c/developer/string-length-calculator/
MLA 9"String Length Calculator." CalcSeed, 17 Nov. 2026, calcseed.com/c/developer/string-length-calculator/.
ChicagoCalcSeed. "String Length Calculator." Last modified November 17, 2026. https://calcseed.com/c/developer/string-length-calculator/

Related calculators

More Developer calculators