Complete Guide to URL Encoding (Percent Encoding)
Published: October 7, 2026 ยท 7 min read ยท By JSON Suite Team
Ever seen %20 in a URL and wondered what it means? That's URL encoding in action โ a critical concept for web developers working with APIs, forms, and query strings. This guide explains everything you need to know.
What is URL Encoding?
URL encoding (also called percent-encoding) is a method of converting characters into a format that can be safely transmitted in URLs. URLs can only contain a limited set of characters from the ASCII character set. Any character outside this safe set must be encoded.
The encoding format is simple: % followed by two hexadecimal digits representing the character's ASCII code. For example, a space (ASCII 32, hex 20) becomes %20.
Why URL Encoding Exists
URLs have reserved characters with special meanings:
?โ starts the query string&โ separates query parameters=โ separates key from value#โ starts the fragment identifier/โ separates path segments
If your data contains these characters, they must be encoded to prevent breaking the URL structure. For example, searching for "Tom & Jerry" requires encoding the & as %26.
Common Character Encodings
| Character | Encoded | Description |
|---|---|---|
| Space | %20 or + | Space character |
! | %21 | Exclamation mark |
# | %23 | Hash/pound sign |
$ | %24 | Dollar sign |
% | %25 | Percent sign |
& | %26 | Ampersand |
+ | %2B | Plus sign |
/ | %2F | Forward slash |
= | %3D | Equals sign |
? | %3F | Question mark |
@ | %40 | At sign |
encodeURI vs encodeURIComponent
JavaScript provides two functions, and choosing the right one matters:
encodeURIComponent() โ For Query Parameters
Encodes everything except: A-Z a-z 0-9 - _ . ! ~ * ' ( )
Use this for encoding values in query strings:
encodeURI() โ For Complete URLs
Preserves URL structure characters: : / ? # [ ] @ ! $ & ' ( ) * + , ; =
Use this when encoding an entire URL that's already properly formed:
The Key Difference
Form Encoding (application/x-www-form-urlencoded)
HTML forms use a slightly different encoding where spaces become + instead of %20. This is called "form encoding" or "application/x-www-form-urlencoded".
Both formats decode to the same result. Most servers accept either, but be consistent within your application.
Unicode and UTF-8 Encoding
Non-ASCII characters (emojis, Chinese, Arabic, etc.) are first converted to UTF-8 bytes, then each byte is percent-encoded:
URL Encoding in Different Languages
Common Mistakes to Avoid
- Double encoding โ Encoding an already-encoded string turns
%20into%2520. Always decode first if unsure. - Using encodeURI for query values โ This leaves
&and=unencoded, breaking your URL. - Forgetting to encode โ User input in URLs can contain anything. Always encode dynamic values.
- Mixing + and %20 โ While both work for spaces, mixing them looks inconsistent. Pick one.
When to Use URL Encoding
- Query string parameters โ
?name=John%20Doe&city=New%20York - Form submissions โ Browser encodes form data automatically
- API requests โ REST API parameters need encoding
- Redirect URLs โ URLs passed as parameters need encoding
- OAuth callbacks โ Redirect URIs must be encoded
URL Encoding vs Base64
These serve different purposes:
- URL encoding โ Makes text URL-safe. Output is human-readable. Use for query strings.
- Base64 encoding โ Converts binary to text. Output is not readable. Use for binary data in JSON or headers.
Try It Yourself
Need to encode or decode URLs quickly? Use our free URL Encoder/Decoder tool. It handles both standard URL encoding and form encoding, supports Unicode, and processes instantly in your browser.