123eworld Knowledge Hub → Transactional SMS → Page 133
Transactional SMS API Unicode, GSM-7 and Message Segmentation: Length Calculation and Cost Control
A developer reference explaining SMS character encoding, GSM-7, Unicode/UCS-2 behaviour, concatenated messages, segment calculation, special characters, billing impact and API validation.
Why SMS length is not just characters
The number of characters a user sees does not always equal the number of SMS segments sent. Encoding determines how much content fits into one segment, and concatenation introduces additional overhead.
GSM-7
GSM-7 supports a defined character set commonly used for Latin-based SMS content. Some characters use escape mechanisms and therefore consume more encoding capacity than ordinary characters.
Unicode
Characters outside the supported GSM-7 set can cause the message to use Unicode encoding. This can substantially reduce the number of characters available per segment.
Concatenated SMS
Long messages are divided into segments and reassembled by the receiving handset. The platform must calculate segments correctly and preserve ordering metadata.
Special characters
A message can unexpectedly switch encoding because of one character such as a smart quote, non-breaking space or currency symbol. Developers should validate real message text rather than relying only on visible character count.
Segment calculation
The API or SDK should expose the selected encoding and estimated segment count where practical. This helps customers understand why a seemingly short message may generate multiple billable segments.
Templates
Templates should be validated with representative dynamic values because inserted customer names or transaction fields can change encoding or length.
Truncation
Automatic truncation can create dangerous results for OTPs, payment information or transaction references. If a message exceeds the configured limit, reject or explicitly segment according to the documented policy rather than silently cutting content.
Cost control
Reducing unnecessary Unicode characters and keeping transactional text concise can reduce segment count and improve delivery efficiency.
Testing
Test ASCII, extended GSM characters, Devanagari, emoji, mixed-language text, dynamic placeholders and maximum-length content.
API design
Return safe metadata such as encoding, segment count and validation errors without exposing sensitive message content in logs.
Implementation checklist
Define encoding detection, segment calculation, concatenation, validation, truncation policy, template testing, cost reporting and multilingual test cases.
Segment-aware billing
Billing should use the actual segment count determined by encoding and message length, not simply one API request equals one SMS. Customers should be able to reconcile usage with the platform's calculation rules.
Encoding preview
A developer portal or SDK can provide an encoding and segment preview before sending. This is especially useful for templates where a single dynamic value can introduce Unicode and increase the number of segments.
Unicode normalization
Do not silently normalize or replace customer text in a way that changes its meaning. If a character forces Unicode encoding, report that fact and let the customer decide whether to modify the content.
Mixed-language templates
Templates containing English, Marathi, Hindi or other scripts should be tested with realistic values. A template that is one segment in English can become several segments after localized content is inserted.
Emoji considerations
Emoji can consume substantially more encoding capacity and can vary in representation. If emoji are supported, segment calculation should be based on actual encoded content rather than visual character count.
Developer reference rule
Treat encoding, segmentation and billing as one technical concern because each depends on the exact bytes and characters sent to the network.
Exact segment calculation
Segment calculation should operate on the final message after template variables are substituted. The encoding decision must therefore occur late enough in the pipeline to reflect the actual text being transmitted.
Extended GSM characters
Some characters require an escape mechanism and consume additional capacity even though the overall message remains within GSM-7. An accurate calculator should account for these characters rather than counting Unicode code points alone.
Unicode and languages
Indian-language messages such as Marathi or Hindi may require Unicode encoding. A customer sending localized transactional content should therefore test both the English and localized versions of every important template.
Segment boundaries
Concatenation headers reduce payload capacity per segment. The API should use the correct rules for the selected encoding and network implementation rather than applying a simple fixed character limit to every message.
Usage transparency
Expose segment count and encoding in usage reports where possible. This lets customers reconcile invoices and identify templates that unexpectedly became multi-segment messages.
Practical scenario
An English OTP template uses one segment. A localized version adds Devanagari text and switches encoding, increasing the segment count. The platform reports the encoding and segment estimate before sending so the developer can decide whether the content should be shortened.
Failure scenario
A template is edited to use a smart quote and suddenly becomes Unicode encoded. Segment count increases and the customer sees higher usage. The platform's preview identifies the encoding change before sending, allowing the developer to shorten or modify the template.
Operational checklist
Verify encoding detection, extended GSM handling, Unicode support, concatenation rules, dynamic-value testing, segment reporting and multilingual test cases.
Developer takeaway
SMS length must be calculated from the encoded final message, not from a simple visual character count.
Design review
Review segmentation logic whenever encoding libraries, SMS providers or template engines change. Small library changes can affect segment calculation and therefore customer billing.
Reference note
Always calculate segments after dynamic template substitution. Static template length is not sufficient evidence.
Final standard
Encoding and segmentation must be deterministic, explainable and testable.
Implementation example
A template contains English text and a customer's Marathi name. The final message is evaluated after substitution, switches to Unicode and requires additional segments. The API returns segment information so the calling system can decide whether to shorten the message or proceed.
Testing standard
Test ASCII, extended GSM, Devanagari, mixed-language content, emoji and dynamic placeholders. Compare calculated segments with provider-side usage in controlled tests.
Final checklist
Confirm billing and usage reporting use the same deterministic segment calculation as message submission.
Capacity example
A template that unexpectedly becomes three segments can triple network workload for a large campaign. Segment preview and usage monitoring therefore provide both cost and capacity protection.
Support guidance
When usage rises unexpectedly, inspect encoding and final rendered message text before assuming the API sent duplicate messages.
Reference rule
The final encoded payload determines segment count and network cost.
Production readiness
Test segment calculation against provider usage using representative multilingual messages. Include dynamic template values because final content determines encoding.
Documentation requirement
Explain GSM-7, extended characters, Unicode and concatenation in developer-friendly language. Provide a segment calculator or SDK helper where practical.
Long-term maintenance
Keep the segmentation algorithm consistent across API validation, SDK previews and billing reports so customers do not receive conflicting numbers.
Architecture review
Perform encoding and segment calculation in one shared library or service used by validation, submission and billing. Separate implementations can otherwise disagree about the same message.
Final implementation note
Test real rendered content, not only templates, because dynamic values can change encoding and segment count.
Final production rule
Do not calculate SMS cost from visible character count alone; use the actual encoding and segmentation rules.
Reference summary
Encoding-aware validation prevents unexpected segment counts, billing surprises and avoidable message fragmentation across multilingual transactional content.
Developer implementation detail
Use one tested encoding library or service for segment estimation across API validation, SDK previews and billing. Store the calculated encoding and segment count with the message attempt so later usage reports can explain how the charge was derived.
Final check
Confirm segment calculations are based on the final rendered message and remain consistent with billing.
Quality standard
Keep encoding calculations deterministic across every customer-facing usage surface.
Final reference point
For multilingual SMS, the final rendered payload is the source of truth for encoding and segmentation. Template-only calculations are insufficient when dynamic values can change the character set.
Final rule
Use final payload encoding for segment calculation.
Closing note
Keep encoding and segment calculations identical in validation, submission and usage reporting.
Check
Verify final-payload segment consistency.
Final check
Keep segment calculation deterministic across SDK, API and billing.
Quality
Keep segment rules unified.
Final check
Verify segment count.
Need transactional SMS integration?
123eworld.com provides Bulk SMS and API-based business communication solutions for enterprises and software applications.