Know more about URL Encoding
A URL is another word for a web address. URL can be composed of words or an IP address. Most people use the name when surfing because names are easier to remember than numbers. URL stands for Uniform Resource Locator. It's used more generally within the main Uniform Resource Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform Resource Name (URN).
URL encoding is the process of converting string into valid URL format. Valid URL format means that the URL contains only what is termed "alpha | digit | safe | extra | escape" characters. Most web programming languages already provide built in method to perform URL Encoding and URL Decoding. It's normally performed to convert data passed via html forms.
Where URL Encoding is the process of converting a string into a valid URL format. The valid URL format means that the URL should not contain any unprintable characters or characters with special meaning. URL Encoding helps to represent unambiguous and universally accepted characters for web browsers and servers.
The most commonly encoded character in URL string is the <space> character. You can see plus-sign (+) whenever space in a URL. The plus sign acts as a special character representing that space in a URL.
How could you encode a URL?
To encode a URL, you simply replace the special characters with their encoding string. Nearly most of the special characters encoding begin with a % character followed by a hexadecimal number.
What should be encoded?
Any character that is not an alphabet, a number, or a special character that is being used outside its normal context is going to need to be encoded in your page.
But, If you were writing special characters for HTML instead of URL then you need to add an ampersand, you could not use %26. Instead, you would use either "&" or "&", both of which would write out the & in the HTML page when rendered.