A worked example
The text hello world?foo=bar encodes to hello%20world%3Ffoo%3Dbar — each unsafe character replaced with its percent-encoded form.
Frequently asked questions
Why do spaces become %20 in a URL?
URLs can't contain literal spaces — %20 is the percent-encoded (hex) representation of the space character, one of several reserved or unsafe characters that need to be escaped this way to appear in a URL.
When do I actually need to URL-encode something?
Whenever you're building a URL programmatically and inserting user input or special characters into a query string or path segment — without encoding, characters like &, ?, #, or spaces can break the URL's structure or be misinterpreted.