URL encoding isn't random - it follows specific rules developed back when the web was being built. Think of it as a translation system that converts "unsafe" characters into a format that won't break anything. The system is called "percent-encoding" because every encoded character starts with a percent sign.
The Safe Character Shortlist
Only these characters can appear in URLs without encoding:
Everything else gets encoded. A space becomes %20 (that's ASCII code 32 in hexadecimal). An ampersand (&) becomes %26. Even the percent sign itself gets encoded as %25 when it's not part of an encoding sequence. This prevents confusion - the system needs to know whether %20 means "a space" or literally the characters "%20".
The encoding process is actually two steps: first, your text gets converted to bytes using UTF-8 (which handles all languages and emojis). Then each byte that's not on the safe list becomes % followed by two hexadecimal digits. Two digits because we're working with bytes, which range from 00 to FF in hex.
Why hexadecimal? It's compact and unambiguous. Early web engineers chose it because it's easy to parse programmatically and creates reasonably short encoded strings. Each percent-encoded sequence is exactly three characters long (% plus two hex digits), which makes decoding straightforward - find %, take next two characters, convert from hex to decimal, you've got your original byte back.