How URL Encoding Works
URL encoding converts text to UTF-8 bytes, then replaces each byte that needs escaping with a % prefix followed by two hexadecimal digits. ASCII characters occupy one UTF-8 byte, while a non-ASCII character may produce several percent escapes.
Common URL Encoded Characters:
| Character | URL Encoded |
|---|---|
| Space | %20 |
| ! | %21 |
| # | %23 |
| & | %26 |
| = | %3D |
| ? | %3F |
| / | %2F |
| : | %3A |
Note: Spaces can also be encoded as + in query strings, but %20 works universally.
URL Encoding Examples
Here are some common URL encoding examples:
| Original | URL Encoded |
|---|---|
hello world! |
hello%20world%21 |
https://example.com?q=hello world |
https%3A%2F%2Fexample.com%3Fq%3Dhello%20world |
file name.txt |
file%20name.txt |
$100 OFF! |
%24100%20OFF%21 |
When to Use URL Encoding
- Query Parameters: Encode values in URLs like ?name=John%20Doe
- Form Submissions: Encode form data submitted via GET requests
- API Requests: Ensure URLs with special characters work correctly
- Database Values: Encode values that will be part of a URL
- File Paths: Encode filenames that contain spaces or special characters