What percent-encoding actually does
A URL has a limited alphabet. Only unreserved characters (letters, digits, and the four marks - . _ ~) may appear literally anywhere. Everything else is either reserved, meaning it carries structural meaning, or simply not allowed.
Percent-encoding is the escape hatch. The character is converted to its UTF-8 bytes, and each byte is written as a percent sign followed by two hexadecimal digits. A space is byte 0x20, so it becomes %20.
The important consequence is that encoding operates on bytes, not characters. Anything outside ASCII produces more than one escape.
space → %20 (1 byte)
& → %26 (1 byte)
é → %C3%A9 (2 bytes)
😀 → %F0%9F%98%80 (4 bytes)This is why an encoded string is always longer than its source, and why the byte count matters when a system imposes a URL length limit.