What is URL Encoding?
URL encoding (percent-encoding) converts special characters in URLs into a safe format using % followed by hex codes. Learn how URL encoding works and why it is necessary.
URL encoding, also known as percent-encoding, is a mechanism to encode special characters in a URL by replacing them with a percent sign (%) followed by two hexadecimal digits representing the character's ASCII code. This is necessary because URLs can only contain a limited set of ASCII characters, and many characters have special meaning in URL syntax.
How URL Encoding Works
Characters are encoded by looking up their ASCII/Unicode value and converting to hex: • Space → %20 (ASCII 32 = 0x20) • : → %3A (ASCII 58 = 0x3A) • / → %2F (ASCII 47 = 0x2F) • @ → %40 • ? → %3F • # → %23 Example: https://example.com/search?q=hello world becomes: https://example.com/search?q=hello%20world
Reserved vs Unreserved Characters
URL characters fall into two categories: • Unreserved — Safe to use as-is: A–Z, a–z, 0–9, -, _, ., ~ • Reserved — Have special meaning in URLs: : / ? # [ ] @ ! $ & ' ( ) * + , ; = Reserved characters must be percent-encoded when used as data (not structure). For example, a query parameter value containing & must be encoded as %26.
URL Encoding in Practice
You encounter URL encoding constantly: • Search queries: google.com/search?q=what+is+api (+ is also valid for space in query strings) • Form submissions: browsers automatically encode form data before sending • File paths with spaces: /my%20documents/file.pdf • Non-ASCII characters: Japanese 日本語 → %E6%97%A5%E6%9C%AC%E8%AA%9E • API calls with special characters in parameters
Try it yourself
Encode/Decode TextAbout URL Encoding
URL encoding is defined by RFC 3986. The web relies on it to safely transmit data that contains characters not allowed in URLs. Without URL encoding, a URL containing a space, ampersand, or non-Latin character would be ambiguous or invalid. Modern browsers handle encoding automatically, but developers must be aware of it when building APIs and handling user input.
FAQ
- Why does %20 mean a space?
- A space character has ASCII code 32, which is 20 in hexadecimal. URL encoding prefixes hex values with %, so space becomes %20.
- What is the difference between URL encoding and Base64 encoding?
- URL encoding makes individual characters safe for URLs, preserving readability. Base64 encoding converts binary data into a text-safe format using 64 printable characters. They serve different purposes and produce different outputs.
- Should I use + or %20 for spaces in URLs?
- In the query string part of a URL (?key=value), + is traditionally valid for spaces (form encoding). In the path part (/my%20file), you must use %20. %20 works everywhere and is safer to use consistently.
Related Tools
Date Calculator
Calculate the difference between two dates in days, weeks, months, and years
Percentage Calculator
Calculate percentages, discounts, increases, and percentage differences
Image Compressor
Compress and resize images to reduce file size while maintaining quality
JSON Formatter
Format and beautify JSON data with syntax highlighting