Skip to content
ENExplore Calculators

String Length

Free String Length calculator with clear step-by-step results.

About String Length

String length has at least three legitimate answers and they routinely disagree. Code points are what a user perceives as characters, UTF-16 code units are what JavaScript's length property returns, and UTF-8 bytes are what a database column or network payload actually consumes.

Formulas

Code points

Count of Unicode scalar values, obtained by iterating the string rather than reading .length

UTF-16 units

The value JavaScript reports as .length; astral characters count as two

Worked example

With the default values below, String Length returns Characters (code points) of 32. Change any input above and every figure here is recalculated in your browser.

Inputs used

Text to measure
Hello, world! Cafe naive resume.
Trim leading and trailing whitespace
Yes
Assumed bytes per character for storage sizingaccepts 1–4 B
1 B

Results

Characters (code points)
32 chars
UTF-16 code units (JavaScript length)
32
UTF-8 bytes
32 B
Words
5 words

Step by step

  1. 1Values used
  2. 2Code points
  3. 3UTF-16 units
  4. 4Characters (code points)= 32 chars
  5. 5UTF-16 code units (JavaScript length)= 32
  6. 6UTF-8 bytes= 32 B
  7. 7Words= 5 words

Assumptions and limits

  • The result is derived only from the 3 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

Why do the three counts differ?

Characters outside the Basic Multilingual Plane - emoji, some CJK extensions - occupy two UTF-16 units and up to four UTF-8 bytes while being one code point.

Which count should a length validator use?

Code points for user-facing limits, UTF-8 bytes for storage limits. Using UTF-16 units silently rejects valid input containing emoji.

String Length – Calculate Characters (code points)