URLs can only contain a limited set of characters defined by RFC 3986. Any character outside this set spaces, Unicode characters, ampersands, equals signs must be percent-encoded to prevent misinterpretation by servers, browsers, and intermediaries. Encode or decode any URL string instantly with the URL Encoder.
How Percent-Encoding Works
Each character is represented as a percent sign followed by its two-digit hexadecimal ASCII code:
- Space →
%20(ASCII 32 = 0x20) &→%26=→%3D#→%23+→%2B(in query strings,+also represents a space)
Unicode characters (non-ASCII) are first converted to UTF-8 bytes, then each byte is percent-encoded. The emoji 😀 encodes to %F0%9F%98%80 four bytes because it is a 4-byte UTF-8 character.
Reserved vs Unreserved Characters
RFC 3986 divides characters into:
- Unreserved A–Z, a–z, 0–9,
-_.~never encoded - Reserved
: / ? # [ ] @ ! $ & ' ( ) * + , ; =have special meaning in URLs; encode when used as data, not structure - Everything else must always be encoded
encodeURI vs encodeURIComponent in JavaScript
JavaScript provides two functions with importantly different behaviour:
encodeURI(url)encodes a complete URL, preserving reserved characters like/,?,#encodeURIComponent(value)encodes a single value to be used inside a URL, encoding reserved characters too
Rule of thumb: use encodeURIComponent() for values in query strings; use encodeURI() for full URLs you do not want to break. The MDN encodeURIComponent documentation explains the exact character exclusions.
Common URL Encoding Mistakes
- Double-encoding encoding an already-encoded URL converts
%20to%2520. Always decode before re-encoding. - Encoding the full URL instead of the value encoding
https://example.com/path?q=hello worldas a whole breaks the structure; onlyhello worldshould be encoded - Using + in path segments
+means space only in the query string (application/x-www-form-urlencoded format), not in URL paths. Use%20in paths.
Frequently Asked Questions
Why does a space sometimes become + and sometimes %20?
In HTML form submissions using application/x-www-form-urlencoded encoding (the default for GET forms), spaces are encoded as +. In standard URL percent-encoding per RFC 3986, spaces must be %20. Most server-side languages handle both, but %20 is unambiguous and correct in all contexts.
Is URL encoding the same as Base64?
No. URL encoding makes specific characters safe for use in URLs. Base64 encoding converts binary data to ASCII text. They solve different problems. For encoding binary data in a URL (such as an image), you would use Base64 encoding of the binary, then URL-encode the Base64 string if necessary. See our Base64 Encoder for binary encoding.