URL encoding (also called percent encoding) converts characters in URLs into a format that can be transmitted safely over the internet. Reserved characters, unsafe characters, and non-ASCII characters are replaced with a % followed by two hexadecimal digits.
URLs can only contain a limited set of ASCII characters. URL encoding replaces unsafe characters with a percent sign followed by their two-digit hex code. For example, a space becomes %20, and a forward slash becomes %2F. The encodeURIComponent() and encodeURI() functions in JavaScript handle this automatically.
Characters are classified as unreserved (A-Z, a-z, 0-9, -, _, ., ~) or reserved (!, #, $, %, &, ', (, ), *, +, ,, /, :, ;, =, ?, @, [, ]). Reserved characters must be encoded if they appear in a context where they would have special meaning. Non-ASCII characters are first encoded as UTF-8 bytes, then each byte is percent-encoded.
Spaces are not allowed in URLs. %20 is the hex encoding of the space character's ASCII value (20 in hex, 32 in decimal).
In query strings, + historically represents a space (application/x-www-form-urlencoded). %20 is the standard percent-encoding for spaces. Modern URLs should use %20.
Most languages follow RFC 3986 standards. The main difference is which characters are considered safe — some tools encode more or fewer characters by default.