Free · No sign-up Client-side

TEXT TRANSFORMATION · TEXT & ENCODING

String Escape / Unescape Calculator

TEXT TRANSFORMATION · TEXT & ENCODING October 2026 12 min read

Escape special characters for C, JavaScript, JSON, Python, HTML or URL contexts, or decode backslash, numeric and percent escapes back into text. Free, instant and entirely client-side.

Backslash escaping is language-specific: C, JavaScript, JSON, Python and regex engines accept different escape sets.

Escape special characters for C, JavaScript, JSON, Python, HTML or URL contexts, or decode backslash, numeric and percent escapes back into text.

Text transformationUnicode-awareClient-sideWorked examples
Cipher alphabet
A–Z / a–z
Caesar key space
26
ROT13 property
reversible
Client-side
100%
Source: No upload

Quick answer

Escape special characters for C, JavaScript, JSON, Python, HTML or URL contexts, or decode backslash, numeric and percent escapes back into text. The calculator applies escaped = Σ escape(char, style); decoded = parse(escaped, style) and shows every intermediate value.

On this page
  1. 1Quick Answer
  2. 2Interactive Calculator
  3. 3String Escape / Unescape Calculator: Character & Byte Breakdown
  4. 4Key Takeaways
  5. 5Developer Statistics
  6. 6Implementation Plans
  7. 7Reference Tables
  8. 8Formulas & How to Use
  9. 9Worked Examples
  10. 10Advanced Education: String Escape / Unescape Calculator
  11. 11Language Playbooks
  12. 12Glossary
  13. 13Mistakes & Pro Tips
  14. 14Use Cases
  15. 15Related Calculators
  16. 16Long-Tail Answers
  17. 17FAQs (19)
  18. 18References

Interactive Calculator

Enter a value — every result updates instantly, in your browser. Free forever, no sign-up.

Private Exact math

String Escape / Unescape Calculator

All inputs are calculated locally with exact integer arithmetic where possible.

Runs in your browser
Text or escaped string Escape mode converts control characters and quotes; unescape mode recognises the selected style plus common numeric escapes.Mode Escape style

Live result

Line 1\n\"quoted\"\t😀

18 input chars · 22 output chars · 24 UTF-8 bytes

escapec

Output

Line 1\n\"quoted\"\t😀

Input length

18

Output length

22

UTF-8 bytes

24

String Escape / Unescape Calculator: Character & Byte Breakdown

Code points, code units, bytes and the exact mapping behind the result.

Calculated values and bit-level details
Output
Line 1\n\"quoted\"\t😀
Input length
18
Output length
22
UTF-8 bytes
24

Escape reference

CharacterC / JSJSONHTMLURL
newline\n\n
%0A
tab\t\t	%09
backslash\\\\\%5C
double quote\"\""%22
less than<<&lt;%3C
ampersand&&&amp;%26

Step-by-step calculation

  1. 1Apply c escaping rules to the input.
  2. 2Leave characters that do not need escaping unchanged.
  3. 3Round-trip the output through the opposite mode to verify it.

Key Takeaways

The 30-second version — the exact answers Google loves to feature.

  • 1Backslash escaping is language-specific: C, JavaScript, JSON, Python and regex engines accept different escape sets.
  • 2HTML escaping should be applied at output time, not stored permanently; double-escaping turns & into &amp;amp;.
  • 3URL percent-encoding operates on UTF-8 bytes, so one non-ASCII character becomes several %XX sequences.
  • 4Encoding and escaping are reversible representations, never encryption.
  • 5Transformations should be tested with ASCII, accented text, CJK and emoji before production.

Developer Statistics & Reference Facts

Numbers worth remembering. Use them to sanity-check inputs, ranges and boundary values before shipping code.

Cipher alphabet
A–Z / a–z
Caesar key space
26
ROT13 property
reversible
Client-side
100%
Source: No upload
Integer math
Exact
Source: BigInt
Transformation mode
Unicode-safe

Implementation Plans Compared: Which Workflow Fits?

Three practical ways to use this calculator. Match the plan to the risk level of your project, then follow its safeguards.

Quick check

Best for: Everyday conversions, debugging and code reviews

  • Method: Paste the text or bytes into the text transformation tool and read the headline result.
  • Precision: UTF-8 byte counts and Unicode code points are exact; display-width estimates are approximate.
  • Safeguards: Cross-check one ASCII value, one accented value and one emoji before trusting a length rule.
Recommended

Production implementation

Best for: Shipping code that reads, stores or transmits text

  • Method: Use an explicit encoding, decode with errors="strict", and keep the byte and character layers separate.
  • Precision: Match the exact encoding and normalization form used by the storage layer or wire protocol.
  • Safeguards: Add tests for ASCII, CJK, emoji, combining marks, embedded NULs and lone surrogates.

Security review

Best for: Input validation, identifiers and URL handling

  • Method: Normalize before comparing, reject unexpected control characters, and encode at the correct output context.
  • Precision: Apply NFC for identifiers and the output-context encoder (HTML, URL, JSON) for the destination.
  • Safeguards: Test homoglyphs, zero-width characters, double encoding and mixed-script input.

Quick Reference Tables

Widths, ranges, boundary values and language types — the lookup tables you will come back to.

Common escapes

CharacterC / JSJSONHTMLURL
New line\n\n&#10;%0A
Tab\t\t&#9;%09
Backslash\\\\&#92;%5C
Double quote\"\"&quot;%22
Less than<<&lt;%3C
Ampersand&&&amp;%26

ROT13 alphabet mapping

PlainABMNZ
CipherNOZAM
Plain (lower)abmnz
Cipher (lower)nozam

Formulas & How to Use This Calculator

Core relationship

escaped = Σ escape(char, style); decoded = parse(escaped, style)

Verification

1. Decode the output with the stated encoding. 2. Round-trip it back to the original and compare. 3. Check the code-point, UTF-16 and UTF-8 counts independently. 4. Repeat with ASCII, accented text, CJK and one emoji.

How to use — step by step

  1. Paste or type the text, bytes or code points into the input panel.
  2. Choose the encoding, notation or transformation mode that matches your data.
  3. Read the headline result — a converted string, a count or a similarity score.
  4. Open the per-character or per-byte breakdown to verify the mapping.
  5. Test one ASCII character, one accented character and one emoji before relying on the rule.
  6. Copy the result and keep the encoding and normalization form documented in your code.

Worked Examples

Real numbers and raw bits, fully worked — copy the pattern for your own code or protocol.

C string

Inputs

Line 1\n"quoted"

Math

newline → \n; quote → \"; backslash → \\

Result

Line 1\n\"quoted\"

JSON

Inputs

Hello 😀

Math

JSON.stringify escapes the surrogate pair

Result

"Hello \uD83D\uDE00"

Unescape HTML

Inputs

&lt;b&gt;Hi&lt;/b&gt;

Math

&lt; → <; &gt; → >

Result

<b>Hi</b>

Advanced Education: String Escape / Unescape Calculator

Beyond the calculator — the mental models, language rules and edge cases professionals use.

Characters, code points and code units are three different things

A user sees a character, Unicode assigns a code point, and an encoding stores one or more code units. “A” is one code point and one UTF-8 byte. “é” is one code point but two UTF-8 bytes. “😀” is one code point, four UTF-8 bytes and two UTF-16 code units. The String Escape / Unescape Calculator reports each layer separately because mixing them is the most common source of off-by-one bugs in length checks, database columns and truncation logic. Decide which layer your requirement actually refers to before you compare a number.

Why UTF-8 length differs from string length

UTF-8 uses one byte for U+0000–U+007F, two for U+0080–U+07FF, three for U+0800–U+FFFF and four for U+10000–U+10FFFF. A string of 100 English letters is 100 bytes, while 100 CJK characters may be 300 bytes and 100 emoji may be 400 bytes. The String Escape / Unescape Calculator encodes the actual text rather than estimating from the character count, so the result is exact. Use byte length for network payloads, database limits and storage budgets, and use code points or graphemes for user-facing character limits.

UTF-16 and surrogate pairs

UTF-16 stores the Basic Multilingual Plane in one 16-bit code unit. Code points above U+FFFF are split into a high surrogate in the range D800–DBFF and a low surrogate in DC00–DFFF. JavaScript, Java and Windows APIs expose UTF-16 lengths, which is why an emoji can count as two characters. The String Escape / Unescape Calculator shows the individual code units and flags surrogate pairs. When slicing user text, never cut between a high and a low surrogate; use a code-point-aware or grapheme-aware API instead.

Encoding conversion is not encryption

Base64, percent-encoding, HTML entities and Unicode escapes are reversible representations, not protection. Anyone can decode them without a key. Use them to move data safely through a text-only channel, not to hide secrets. The String Escape / Unescape Calculator makes the transformation transparent and copy-ready. If the data is sensitive, encrypt it first with an authenticated cipher, then encode the ciphertext for transport. Encoding changes the alphabet; encryption changes who can read the message.

Escaping rules are language-specific

JSON uses \uXXXX for control characters and allows a limited set of short escapes. JavaScript accepts \xXX, \uXXXX and \u{...}. Python distinguishes \x, \u and \U. C uses octal and hexadecimal escapes with different termination rules. The String Escape / Unescape Calculator applies one explicit convention at a time so the output matches the target language. When generating code or configuration, prefer a standard library serializer over hand-built string concatenation; it handles quotes, backslashes and control characters consistently.

Security: normalization and homoglyphs

Two different code-point sequences can render identically. “é” can be a single precomposed code point or “e” plus a combining acute accent. Unicode normalization (NFC or NFD) makes comparisons consistent. Homoglyphs from different scripts can impersonate Latin letters in usernames and URLs. The String Escape / Unescape Calculator reveals the underlying code points so you can spot invisible characters, zero-width joiners and mixed scripts. Normalize before comparing identifiers, and restrict allowed scripts where impersonation is a risk.

Length limits in databases and APIs

Database columns usually limit bytes or characters, and the definition varies by engine. MySQL VARCHAR(n) counts characters in the column charset; PostgreSQL varchar(n) counts characters; a byte-oriented API may count UTF-8 bytes. A 200-character emoji string can exceed a 255-byte limit. Check the actual unit, measure with the same encoding the storage layer uses, and leave headroom for normalization and future schema changes. The String Escape / Unescape Calculator gives you both counts from the same input.

Testing text transformations with edge cases

A text tool that works for “Hello” may fail for emoji, combining marks, right-to-left scripts or lone surrogates. Build a small corpus: ASCII, accented Latin, CJK, an emoji, a flag, a family emoji with zero-width joiners, a newline, a tab, quotes and a backslash. Run the transformation in both directions and compare the round trip. The String Escape / Unescape Calculator is useful for generating expected output, but the final assertion should run in the target runtime and version.

Language & Platform Playbooks

The same bit pattern behaves differently in every language. Here is how to adapt the conversion safely.

Python

Python 3 strings are sequences of Unicode code points. Use len(text) for code points, len(text.encode('utf-8')) for UTF-8 bytes, and the unicodedata module for normalization. For string escape / unescape calculator, prefer str.encode/decode with an explicit codec and errors='strict' so invalid input fails loudly. The standard library handles surrogate pairs and most legacy codecs; do not hand-roll UTF-8 parsing.

JavaScript / TypeScript

JavaScript strings are UTF-16 code units. Use Array.from(text) for code points, TextEncoder/TextDecoder for UTF-8, and Intl.Segmenter for grapheme clusters where available. For string escape / unescape calculator, avoid split('') on text that may contain emoji; it splits surrogate pairs. Buffer and btoa are not available in browsers, so use TextEncoder plus a small Base64 helper.

Java / Kotlin

Java String.length() counts UTF-16 code units; codePointCount() counts code points. Use StandardCharsets.UTF_8 with getBytes and new String for byte conversion, and Normalizer for NFC/NFD. Kotlin’s String is the same UTF-16 representation. For string escape / unescape calculator, specify the charset explicitly instead of relying on the platform default.

Go

Go strings are immutable byte sequences, usually UTF-8. Ranging over a string yields runes (code points); len(s) yields bytes. Use utf8.RuneCountInString for code points, []rune(s) for rune slices, and golang.org/x/text/unicode/norm for normalization. For string escape / unescape calculator, validate with utf8.ValidString when the input may be malformed.

Rust

Rust strings are guaranteed UTF-8. Use .chars() for code points, .bytes() for bytes, and the unicode-segmentation crate for grapheme clusters. Slicing a String by byte index can panic if it lands inside a code point. For string escape / unescape calculator, work with char_indices() when you need both position and character, and use encoding_rs for legacy encodings.

C / C++

C and C++ distinguish char, wchar_t, char16_t and char32_t. UTF-8 is usually stored in char arrays; convert with codecvt, ICU or a dedicated library rather than manual byte surgery. For string escape / unescape calculator, keep the byte length separate from the display width and validate the input before conversion. Do not assume wchar_t is 32-bit on every platform.

Glossary: Key Terms Explained

ROT13
A Caesar shift of 13 positions; applying it twice restores the original text.
Caesar cipher
A substitution cipher that shifts each letter by a fixed number of positions in the alphabet.
Escape sequence
A backslash sequence that represents a character that would otherwise be hard to type or ambiguous.
Percent-encoding
The URL-safe encoding of bytes as %HH hexadecimal pairs.
Bit
A binary digit: 0 or 1. Bits are grouped into bytes, words and registers.
Byte
Eight bits. A byte is the smallest addressable unit on most CPUs and the usual unit for file sizes.
Word
The natural register width of a CPU. On modern 64-bit systems a word is usually 64 bits, though C’s int is often 32 bits.
MSB / LSB
Most significant bit and least significant bit. The MSB carries the largest positional weight and is the sign bit in signed integers.

Common Mistakes & Pro Tips

Mistakes that break conversions

  • Treating an encoding or escape as a security boundary.
  • Testing only ASCII text and ignoring emoji, combining marks and control characters.
  • Counting UTF-16 code units and calling them characters; JavaScript and Java lengths are not character counts.
  • Decoding bytes with the wrong encoding, which produces mojibake instead of an error.
  • Treating Base64, percent-encoding or HTML escaping as encryption; all three are reversible by anyone.
  • Truncating between surrogate halves or inside a multi-byte UTF-8 sequence.

Pro tips for production code

  • Prefer the platform encoder over hand-written escaping.
  • Test one emoji and one control character with every transformation.
  • Specify the encoding at every boundary: file, network, database and display.
  • Normalize identifiers with NFC before comparing them, and reject control or zero-width characters where they serve no purpose.
  • Use byte length for storage limits and grapheme clusters for user-facing character limits.
  • Prefer the platform encoder or serializer over hand-built escaping; it handles the edge cases you will forget.

Who Should Use This Calculator?

  • ▸ Safe transport through URLs, HTML and JSON.
  • ▸ Debugging escaped configuration and log output.
  • ▸ API validation: confirm that a payload fits a byte limit before sending it.
  • ▸ Database sizing: translate character limits into bytes for the actual column encoding.
  • ▸ Debugging: explain mojibake, double-encoded URLs and invisible Unicode characters.
  • ▸ Security review: detect homoglyphs, zero-width joiners and mixed-script identifiers.

Related Programming Calculators

Keep going — every tool below links directly into this workflow.

People Also Search For

Tap a long-tail question to jump to the matching FAQ answer.

Frequently Asked Questions (19)

Long-tail answers: each question targets a real Google search about string escape / unescape calculator — click to expand.

Showing 19 of 19 answers.

Which style should I choose for a JSON string?
Choose JSON. JSON permits a small set of short escapes (\", \\, \/, \b, \f, \n, \r, \t) and \uXXXX for other control characters. It does not accept C-style \xNN or JavaScript \u{...} escapes, so using the wrong style produces invalid JSON.
Can I unescape a string that was escaped twice?
Run unescape twice and compare the intermediate result. Double escaping commonly happens when a value passes through a template engine and then a JSON serializer. Prefer fixing the layer that escapes twice over repeatedly unescaping, because blind double-unescaping can corrupt legitimate backslashes.
What does the string escape / unescape calculator show?
Escape special characters for C, JavaScript, JSON, Python, HTML or URL contexts, or decode backslash, numeric and percent escapes back into text. The core relationship is escaped = Σ escape(char, style); decoded = parse(escaped, style). The headline card shows the primary answer, and the breakdown shows the intermediate values so you can check each step.
How do I verify a string escape / unescape calculator result?
Round-trip the result through the inverse operation and compare it with the original. Then test an ASCII character, an accented character, a CJK character and an emoji; if all four behave correctly, the encoding path is probably sound.
What is a common mistake when using the string escape / unescape calculator?
Treating an encoding or escape as a security boundary.
Is ROT13 encryption?
No. ROT13 is a fixed substitution that provides no key and no security; it only hides text from a casual glance. Applying ROT13 twice returns the original. Use a modern authenticated cipher such as AES-GCM or ChaCha20-Poly1305 when confidentiality matters.
Why does a Caesar cipher preserve spaces and digits?
A classical Caesar cipher shifts letters only. Spaces, punctuation, digits and non-Latin characters pass through unchanged, which is why the ciphertext keeps the original word boundaries and is easy to break. A real encryption scheme must hide the entire message, not just its letters.
Does the String Escape / Unescape Calculator count characters or bytes?
It reports both, because they answer different questions. Characters usually means Unicode code points or grapheme clusters; bytes depend on the encoding. “😀” is one code point, two UTF-16 code units, four UTF-8 bytes and four UTF-32 bytes. Use the character count for user-facing limits and the byte count for storage, network payloads and database columns.
Which Unicode version does the String Escape / Unescape Calculator use?
The browser’s JavaScript engine supplies the Unicode data, which tracks a recent Unicode release. Code-point arithmetic is stable, but the set of assigned characters, case mappings and grapheme rules can change between versions. For a compliance-sensitive product, test with the Unicode version bundled in your target runtime rather than assuming every environment is identical.
Why does the String Escape / Unescape Calculator show a different length from JavaScript?
JavaScript String.length counts UTF-16 code units, not code points or graphemes. An emoji outside the Basic Multilingual Plane counts as two units, and a family emoji joined with zero-width joiners counts as many more. The String Escape / Unescape Calculator shows code points, UTF-16 units, graphemes and UTF-8 bytes separately so you can pick the measure your requirement actually uses.
Is the String Escape / Unescape Calculator safe for confidential text?
Yes. The conversion runs entirely in your browser and nothing is uploaded, logged or stored. That said, avoid pasting production secrets into any web page unless your organization’s policy allows it. For regulated data, use an approved local tool or a self-hosted build.
Why do I see a replacement character (�) in the String Escape / Unescape Calculator output?
A replacement character means the input bytes were not valid in the selected encoding. This commonly happens when UTF-8 bytes are decoded as Latin-1, when a multibyte sequence is truncated, or when a lone surrogate is encoded. Check the source encoding first, then verify that the input length is a whole number of code units for that encoding.
Can the String Escape / Unescape Calculator handle emoji and combining marks?
Yes. The engine iterates by Unicode code point rather than by UTF-16 index, so emoji outside the BMP are treated as one code point. Combining marks remain separate code points unless you normalize the text first; use NFC or NFD when you need a canonical comparison. Grapheme counts use Intl.Segmenter when the browser provides it and fall back to code points otherwise.
What is the string escape / unescape calculator used for?
Escape special characters for C, JavaScript, JSON, Python, HTML or URL contexts, or decode backslash, numeric and percent escapes back into text. Developers use it to check a conversion before shipping code, to reproduce a protocol test vector, or to explain a bit pattern in a code review. The page shows the headline result first, then the intermediate values so you can verify each step rather than trusting a black box.
How do I read the string escape / unescape calculator result?
Start with the headline card: it shows the primary answer in the unit or base you selected. The rows below list the same result in decimal, hexadecimal and binary where applicable, plus the mask, width or field details. The technical breakdown then shows the bit groups, intermediate values and a short explanation of each step.
What formula does the string escape / unescape calculator use?
escaped = Σ escape(char, style); decoded = parse(escaped, style) The calculator evaluates that relationship with the values you enter and prints the substitution. For width-dependent operations it masks to the selected number of bits, so the result matches fixed-width hardware rather than unbounded integer arithmetic.
What is a common mistake when using string escape / unescape calculator?
Treating an encoding or escape as a security boundary.
How do I verify a string escape / unescape calculator result by hand?
Repeat the operation with the smallest possible example, such as 0, 1 or a single set bit, and check the pattern against the formula. Then try a boundary value and confirm the wrap or saturation behavior. Finally, compare the hex and binary rows; if they disagree with the decimal row, the input format or width is probably wrong.
Does the string escape / unescape calculator work offline?
Once the page has loaded, all calculations run in the browser and do not require a network request. You can keep the tab open while you work offline. The page itself is served from the web, so the first load needs a connection, but your values are never transmitted to a server.

Resources & Authoritative References

Further reading

Authoritative sources

Was this calculator helpful?

Last updated: October 2026 · Free forever · No sign-up · Part of Programming Calculators at Atlascalcs.com · All math runs in your browser