URL Encoder / Decoder

URLs can only contain a safe subset of ASCII characters; spaces, ampersands, equals signs, and non-ASCII characters must be percent-encoded before they can appear in a URL without ambiguity. For example, a space becomes %20 and a plus sign becomes %2B. Failing to encode query parameters that contain special characters causes form submissions and API calls to break or silently pass incorrect values.

S. Siddiqui

Edited by

S. SiddiquiFounder & Editor-in-Chief
Sources:MDN Web DocsW3CIETFUpdated Jul 2026
Output appears here...

What Is URL Encoding?

URL encoding, formally defined as percent-encoding in RFC 3986, is a mechanism for representing arbitrary data within a Uniform Resource Identifier (URI) using only the limited character set that the internet's foundational protocols accept. The web was built on ASCII, a character set of 128 characters, and URIs are even more restrictive: they may only contain a defined subset of ASCII characters. Every other character, whether a space, an ampersand, a pound sign, a non-Latin letter, or an emoji, must be translated into a safe representation before it can travel inside a URL.

The translation follows a straightforward rule. The offending character is replaced by a percent sign (%) followed by two hexadecimal digits that represent that character's byte value in UTF-8. A space, for instance, has a byte value of 32 decimal, which is 20 in hexadecimal, so it becomes %20. The at-sign (@) becomes %40. An ampersand (&) becomes %26. The percent sign itself, since it is the escape marker, becomes %25.

There are two categories of characters in a URI. Unreserved characters (the letters A-Z and a-z, digits 0-9, and the symbols hyphen, underscore, full stop, and tilde) may appear in any URL without modification. Reserved characters (such as / ? # [ ] @ ! $ & ' ( ) * + , ; =) carry structural meaning within a URI and must be percent-encoded when used as literal data rather than as delimiters. Every other character, including all non-ASCII text, must also be encoded.

URL encoding is not optional or decorative. Without it, a URL containing a space is technically malformed. Without it, an ampersand embedded in a query value would be misread as a parameter separator. Without it, a hash inside a link target would be mistaken for the start of a fragment identifier. Percent-encoding resolves all of these ambiguities by marking exactly which characters are data and which are structural syntax.

It is worth understanding the distinction between two closely related JavaScript functions that reflect this same split. encodeURIComponent() on MDN Web Docs encodes everything except the unreserved set, making it appropriate for encoding individual query values and path segments. encodeURI(), by contrast, leaves reserved characters and the URL structure intact, making it suitable for encoding a complete URL that is already well-formed. The distinction matters in practice: use encodeURIComponent() on the values inside a URL, and encodeURI() on the URL as a whole.

URL decoding is the reverse operation. A percent-encoded string is parsed for every %XX sequence, each sequence is converted back to its original byte, and the bytes are interpreted as UTF-8 text. The result is the original, human-readable string. Decoding is what happens when your browser displays a search result URL as readable text in the address bar, even though the underlying link contains nothing but ASCII.

How to Use the URL Encoder / Decoder

  1. Choose your operation. Select either Encode or Decode depending on what you need. Encoding converts plain text into a percent-encoded format safe for URLs. Decoding reverses that process and returns a percent-encoded string to its original readable form.
  2. Paste or type your input. Enter the text, query value, or full URL into the input field. For encoding, paste the raw value you wish to embed inside a URL, such as a search phrase, a file path, or a parameter value. For decoding, paste the encoded string you have received, perhaps copied from a browser address bar, an API response, or a server log.
  3. Run the conversion. Click the Encode or Decode button. The tool processes your input instantly and displays the result in the output field.
  4. Copy the result. Use the copy button or select all text in the output field. The encoded string is ready to paste directly into a URL, API call, configuration file, or code. The decoded string is ready for human reading, debugging, or further processing.
  5. Verify the output. Before using an encoded value in a production URL or API request, check that reserved structural characters you did not intend to encode remain untouched, and that characters which must be encoded have been replaced with their correct %XX sequences.

Why Use This Tool

Constructing percent-encoded strings by hand is tedious and error-prone. The hexadecimal values for common characters are not intuitive, and a single wrong digit produces an invalid or misread URL. A dedicated encoder removes all of that manual arithmetic and guesswork, producing correct output in a fraction of a second.

Beyond convenience, the tool ensures consistency. Different programming languages, frameworks, and libraries implement URL encoding with subtle differences. Some replace spaces with + rather than %20. Some encode characters that others treat as safe. When you need a canonical, RFC-compliant encoding, using a dedicated tool guarantees the result matches the specification rather than the quirks of whichever library your application happens to use.

The decoder is equally valuable for debugging. When a URL arrives in a server log, an API error message, or a browser's network inspector, it is often fully or partially encoded. Reading %E2%80%93 and deducing that it is an en-dash requires knowing UTF-8 byte sequences off by heart. Pasting the string into a decoder gives you the readable form instantly, which makes diagnosing malformed requests, unexpected characters, and encoding mismatches far quicker.

For developers working with third-party APIs, URL encoding is a constant concern. Query parameter values passed to search APIs, mapping services, payment gateways, and authentication endpoints must be encoded correctly, or the receiving server will reject the request or silently misinterpret the data. The tool allows you to verify your encoding before it leaves your development environment, reducing the debugging cycle caused by server-side rejections.

Non-developers benefit as well. Marketers building UTM-tracked links, content managers copying product URLs with special characters, and analysts constructing query strings for reporting tools all encounter URLs that contain characters requiring encoding. This tool removes the need to understand the underlying specification and simply produces the correct output.

Real-World Use Cases

Search engine query strings. A user searching for C++ primer (5th edition) produces the query string ?q=C%2B%2B+primer+%285th+edition%29. The plus signs and parentheses must be encoded, otherwise the server either rejects the request or interprets the plus signs as additional parameter separators. Encoding ensures the full phrase reaches the server intact.

E-commerce product URLs. Products with names like Men's Waterproof Jacket & Hood cannot appear literally in a URL. The apostrophe becomes %27, the ampersand becomes %26, and the spaces become %20 or + depending on context. Shops that auto-generate URLs from product names rely on encoding to prevent broken links.

API requests with compound parameters. REST APIs frequently accept filter values, date ranges, and JSON snippets as query parameters. A date range like 2024-01-01 to 2024-12-31 must be encoded before it can be appended to a URL, because the spaces would terminate the parameter prematurely without encoding. Similarly, a JSON fragment like {"status":"active"} contains curly braces, quotes, and colons that all require encoding.

OAuth and authentication flows. OAuth 2.0 redirect URIs are passed as query parameters within authorisation requests. A redirect URI like https://example.com/callback?source=login must itself be percent-encoded when embedded inside the authorisation URL, because the slashes, colons, and question mark it contains would otherwise break the outer URL's structure.

Email marketing links. UTM parameters in campaign URLs often contain spaces, slashes, and pipe characters as part of campaign names and source identifiers. Encoding these parameters ensures that every tracking click registers correctly in analytics platforms and that no character in the campaign name corrupts the URL structure.

Multilingual and internationalised URLs. A page titled in Arabic, Chinese, or any non-Latin script requires every character to be encoded for transport, even though modern browsers display the decoded form in the address bar for readability. Encoding allows these pages to be linked and shared correctly across all systems, regardless of locale settings.

Debugging server logs. When a request fails, server logs often record the raw percent-encoded URL. Decoding it reveals the original search term, file path, or parameter value that the client sent, which is often the fastest way to identify what went wrong. A 400 Bad Request that looks mysterious in encoded form frequently becomes obvious once decoded.

Web scraping and data extraction. Scrapers that follow pagination links, collect search result URLs, or extract resource paths from HTML attributes regularly encounter percent-encoded strings. Decoding them before storage or comparison prevents duplicate entries caused by the same URL appearing in both encoded and decoded form.

Common Mistakes and Troubleshooting

Double encoding. The most frequent URL encoding bug is encoding an already-encoded string a second time. When %20 is encoded again, the percent sign itself becomes %25, producing %2520. The server then either decodes it to the literal string %20 rather than a space, or rejects the request entirely. The fix is to decode the string first to verify its current state before encoding. Store raw, unencoded values in your data layer and encode them only at the point where you construct the URL.

Encoding the entire URL instead of just the parameter values. A common misunderstanding is feeding a complete URL into an encoder. This converts the slashes, colons, and question marks that give the URL its structure into percent-encoded sequences, producing a string that is no longer a valid URL. Encoding applies to the values within a URL, not the URL's structural characters. Encode each query parameter value individually, then assemble the full URL.

Confusing space encoding conventions. The HTTP specification allows spaces to be encoded as either %20 or + in query strings, but only in query strings, not in path segments. The + convention comes from the HTML form encoding type application/x-www-form-urlencoded. If you copy a query value from one context and paste it into another that expects the other convention, spaces will either be misread or appear as literal plus signs. When in doubt, use %20, which is valid everywhere.

Forgetting to encode the percent sign itself. If your data contains a literal percent sign, for example a discount value of 50%, that percent sign must be encoded as %25. Leaving it unencoded means the server will attempt to interpret whatever follows it as a hexadecimal pair, which produces garbled output or a parsing error.

Mishandling non-ASCII characters. URL encoding for non-ASCII text is a two-step process: the character is first converted to its UTF-8 byte sequence, and then each byte is percent-encoded. A common mistake is encoding non-ASCII characters using a different character set such as Latin-1, which produces different byte sequences and therefore different percent-encoded strings. Always use UTF-8 as the base encoding, which is what all modern browsers and servers expect.

Decoding a URL that was never encoded. Running a decoder over a plain URL that happens to contain a percent sign followed by two hexadecimal digits will corrupt it. For example, sale%off would cause a decoder to attempt to read %of as a percent-encoded sequence, which is invalid, and most decoders will either throw an error or produce unexpected output. Verify that the string you are decoding is actually percent-encoded before running it through a decoder.

Last reviewed: July 1, 2026
Founder's Real-World Experience
S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief, YourToolsBase

How I fixed broken sitemap URLs caused by special characters in category names

When I was building the sitemap for YourToolsBase, I generated it programmatically from the database, pulling in all tool slugs and category paths. The sitemap validator came back with 14 malformed URL errors. I worked through the list and found that all of them belonged to categories whose names contained special characters: things like "C++ Tools", "Text & String", and "Health (BMI & Body)". The ampersands, parentheses, and plus signs had been dropped straight into the URL path without encoding.

I took each of the raw strings, ran them through this encoder, and compared the output against what was in the sitemap. As RFC 3986, the URI specification, makes clear, characters outside the unreserved set must be percent-encoded. The ampersand in "Text & String" was coming through as a literal & in the URL, which is a reserved character that query string parsers interpret as a parameter separator. As a result, the path was being parsed incorrectly by validators and some crawlers. The encoder showed me the correct encoded form for each string, which I then used to update the slug generation logic in the build script.

Given that the sitemap feeds both Google Search Console and the internal link structure, getting those URLs right was not optional. After the fix, all 14 errors cleared and the sitemap was accepted cleanly. What is more, I added the encoding step directly into the category slug generator so the same problem cannot come up again when new categories are added.

14 sitemap URL errors resolvedRFC 3986 compliant slugsEncoding built into slug generator permanently
Also used alongside: Base64 Encoder

Frequently Asked Questions

What is URL encoding?
URL encoding, also called percent-encoding, is the process of replacing characters that cannot appear safely in a URL with a percent sign followed by two hexadecimal digits representing the character's byte value. For example, a space becomes %20 and an ampersand becomes %26. It is defined formally in RFC 3986 and ensures that any data can be transmitted reliably inside a URI.
Why do URLs contain percent signs and numbers?
Percent signs in a URL indicate that the characters following them are percent-encoded. The two digits after the percent sign are a hexadecimal representation of the character's UTF-8 byte value. For instance, %20 represents a space (byte value 32 decimal, 20 hexadecimal) and %2F represents a forward slash. Browsers typically display the decoded, human-readable form in the address bar, but the underlying link uses the encoded format.
What is the difference between %20 and + for spaces in a URL?
Both %20 and + represent a space, but they are valid in different parts of a URL. The %20 encoding is defined by RFC 3986 and is valid anywhere in a URL, including path segments and query strings. The + encoding for spaces comes from the HTML form encoding standard application/x-www-form-urlencoded and is only valid inside query strings, not in path segments. When in doubt, use %20 as it is universally accepted.
What characters need to be URL encoded?
Any character that is not in the unreserved set must be encoded. The unreserved set consists of letters A-Z and a-z, digits 0-9, and the four symbols hyphen (-), underscore (_), full stop (.), and tilde (~). Reserved characters such as /, ?, #, &, =, and @ must be encoded when used as data rather than as URL delimiters. All non-ASCII characters, including accented letters, Chinese characters, Arabic script, and emoji, must also be encoded after first converting them to UTF-8 byte sequences.
What is double encoding and how do I fix it?
Double encoding occurs when an already percent-encoded string is encoded a second time. The percent sign in %20 itself gets encoded to %25, producing %2520 instead of the intended %20. The result is that the receiving server decodes the string to %20 rather than a space. The fix is to always store raw, unencoded values and encode them only at the moment you construct the URL. If you are unsure whether a string is already encoded, decode it first before re-encoding.
What is the difference between encodeURI and encodeURIComponent in JavaScript?
encodeURIComponent encodes all characters except the unreserved set (A-Z, a-z, 0-9, -, _, ., ~), including structural URL characters like /, ?, &, =, and #. It is intended for encoding individual query parameter values and path segments. encodeURI encodes everything encodeURIComponent does except the reserved characters that give a URL its structure, so it is intended for encoding a complete URL that is already well-formed. For encoding a parameter value that will be placed inside a URL, always use encodeURIComponent.
Can I URL encode an entire URL?
You can technically encode an entire URL, but doing so converts the structural characters (slashes, colons, question marks) into percent-encoded sequences, which destroys the URL's structure. The result is a string that is no longer a valid URL. URL encoding is meant to be applied to the data values within a URL, not to the URL itself. If you need to pass a URL as a query parameter value inside another URL, encode only the inner URL and leave the outer URL structure intact.
How does URL encoding handle non-English characters?
Non-ASCII characters, including accented letters, Chinese, Arabic, Cyrillic, and other scripts, are first converted to their UTF-8 byte representation, and then each byte is percent-encoded individually. For example, the Chinese character for 'you' has the UTF-8 byte sequence E4 BD A0, so it becomes %E4%BD%A0 in a URL. Modern browsers handle this automatically and display the decoded characters in the address bar for readability, but the actual URL uses the percent-encoded form.
Why does my server receive garbled text when I submit a form?
Garbled text in form submissions usually means there is a mismatch between the character encoding the form used to encode the data and the encoding the server used to decode it. The most common cause is the server expecting UTF-8 but receiving data encoded in another character set, or vice versa. Always declare the character set of your HTML form explicitly using the accept-charset attribute and ensure your server decodes incoming data as UTF-8. Running the received encoded string through a decoder can help you identify which encoding was actually used.
Is URL encoding the same as HTML encoding?
No. URL encoding (percent-encoding) and HTML encoding are different systems designed for different contexts. URL encoding replaces unsafe URL characters with %XX sequences and is used to transmit data safely inside a URI. HTML encoding replaces characters that have special meaning in HTML markup, such as < becoming &lt; and & becoming &amp;, and is used to display text safely inside an HTML document without it being interpreted as markup. Confusing the two and applying the wrong encoding in the wrong context is a common source of bugs and security vulnerabilities.

Formula

Rate This Tool

Was this tool helpful?

Be the first to rate this tool

💡 Pro Tip

Encode query parameter values, not the entire URL. Encoding the whole URL will break the slashes and colons that make it a valid URL.

About the Author

S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief

LinkedIn Profile

S. Siddiqui is the founder and editor-in-chief of YourToolsBase, overseeing all content, tool accuracy, and editorial standards.

View full profile

Authoritative Sources

Formulas and data in this tool are based on guidelines from the above sources.