Skip to content
Developer Toolkit IconDeveloper Toolkit
All Articles

One Curly Apostrophe Tripled an SMS Bill. Why Every Character Counter Gives a Different Answer

Why a character counter, a database, and an SMS gateway report different lengths for the same text, and how emoji, UTF-16, and reading time change the math.

By Muhammad Zeeshan~5 min read
One Curly Apostrophe Tripled an SMS Bill. Why Every Character Counter Gives a Different Answer

A team shipped appointment reminders by text message. The copy was 150 characters, so they pasted it into a character counter, saw 150, and relied on the one-message limit of 160. Reasonable. The first invoice from the SMS provider showed three billable segments per message instead of one.

Nothing in the code had changed. The copy had been drafted in a shared doc, and somewhere on the way into the template the apostrophe in "Don't forget your appointment" had turned into a curly one. That single character moved the whole message to a different encoding, and the carrier started counting a different way.

The character counter wasn't wrong. It just wasn't counting the thing the carrier counts.

Why One Character Changes the Price

A standard SMS can use the GSM 7-bit alphabet. In that encoding one message holds 160 characters, or 153 per part once a message gets long enough to be split and stitched back together. The alphabet is small. It covers basic Latin letters, digits, common punctuation, and a handful of accented characters. It does not include the curly apostrophe (U+2019), most smart quotes, or any emoji.

One character outside that set and the whole message switches to UCS-2, which uses two bytes per character. The limits drop to 70 characters for a single message and 67 per part for a long one.

Run the numbers on the reminder. At 150 characters in GSM 7-bit, it's one segment. Add one curly apostrophe, and 150 characters in UCS-2 needs ceil(150 / 67), which is three segments. Same text, three times the cost.

Emoji make it worse. An emoji sits outside the Basic Multilingual Plane, so UCS-2 style encodings store it as a surrogate pair, two 16-bit units. Every emoji spends two of your 70 slots.

Straight quotes fix the apostrophe problem. Before text reaches your SMS provider, normalise the usual offenders:

javascript
function straightenQuotes(text) {
  return text
    .replace(/[‘’]/g, "'")
    .replace(/[“”]/g, '"');
}

If the message really does need an emoji, budget 70 characters, not 160, and let the provider's response tell you how many segments it actually used. Most gateways return the segment count with the send result.

Four Things "Length" Can Mean

When someone says a string is 8 characters long, there are at least four defensible answers. Here's the same handful of strings counted four ways:

StringUTF-16 unitsCode pointsGraphemesUTF-8 bytes
A1111
é (one code point)1112
é (e plus a combining accent)2213
😀2114
👨‍👩‍👧85118

The two é rows look identical on screen and aren't equal as strings. The family emoji is three emoji glued together with zero-width joiners, so a person sees one symbol and JavaScript sees eight units.

JavaScript gives you all four counts, but only the first one by default:

javascript
const s = '👨‍👩‍👧';

s.length;                                    // 8   UTF-16 code units
[...s].length;                               // 5   code points
[...new Intl.Segmenter().segment(s)].length; // 1   what a person would count
new TextEncoder().encode(s).length;          // 18  UTF-8 bytes

Intl.Segmenter works in current browsers and in Node 16 and later. If you're validating a username length or truncating a display name, it's the one that matches what the user sees. Truncating with s.slice(0, 5) on that family emoji cuts it into broken pieces.

Where Each Count Shows Up

The counts aren't interchangeable, and each layer of a typical stack picks its own.

  • JavaScript .length counts UTF-16 units. It's what most form validation uses without anyone choosing it.
  • PostgreSQL varchar(n) and char_length() count characters in the code point sense. octet_length() gives bytes.
  • MySQL VARCHAR(n) counts characters too, CHAR_LENGTH() returns characters, and LENGTH() returns bytes. A column that holds 255 characters can need over 1,000 bytes with utf8mb4.
  • SMS counts encoding slots, as above.
  • Search results don't use a character limit at all. Google truncates titles and meta descriptions by pixel width. About 155 characters is a rule of thumb that survives most of the time.

Platforms that publish a limit usually define their own counting rule. Weighted counting, where some characters cost more than others, is common. Before you trust any generic counter for a hard limit, find out which rule the destination applies.

Words Are Less Well Defined Than They Look

Counting words feels safer than counting characters. Mostly it is, until it isn't.

The usual method splits on whitespace. That makes don't one word, state-of-the-art one word, and a pasted URL one word. It also makes a paragraph of Japanese or Chinese count as one word, because those languages don't put spaces between words. For text in those scripts, count characters instead. Any English-centric word counter will give you a number that means nothing.

Reading time is a rougher estimate again. Most calculators divide the word count by a reading speed. A large meta-analysis of silent reading research put the average adult at about 238 words per minute for non-fiction and 260 for fiction. Many tools round down to 200 to stay conservative. Both are fine for a "5 min read" badge. Neither accounts for code blocks, tables, or a reader skimming for the one command they need, which is why reading time on a technical doc is nearly always an overestimate.

Keyword density has the same flavour of problem. It's a count of how often a word appears divided by total words, and it only tells you something when you pass it a whole, clean document.

Checking Text Before It Ships

For a quick answer, paste the text into the word and character counter. It reports words, characters with and without spaces, sentences, paragraphs, reading time, and the most repeated words, and nothing leaves your browser. Its character count follows JavaScript's .length, so an emoji shows up as 2. That's the same way a UCS-2 SMS slot count sees it, and it's why it won't always match what your database reports.

When a count surprises you, look at the characters rather than the total. Paste the suspect string into the Unicode lookup and read the code points. A U+2019 where you expected U+0027 is the whole mystery behind the SMS invoice. A stray U+200B zero-width space is a common reason two strings that look identical won't compare equal.

Free Developer Tools

Put the knowledge to work.

50 browser-based tools. No account. No data sent to a server.