What is URL Shortening?
A URL shortener takes a long web address and produces a much shorter one that redirects to the original. The short URL typically lives on a dedicated domain -- like bit.ly, t.co, or tinyurl.com -- and consists of a base domain followed by a short alphanumeric code. When someone clicks the short link, the shortening service looks up the code in its database, finds the corresponding long URL, and sends an HTTP redirect response that sends the browser to the final destination. The entire process takes milliseconds and is invisible to the end user. They click a 20-character link and land on a page whose real URL might be 200 characters long.
The mechanics under the hood are straightforward. When you submit a long URL, the service generates a unique identifier for it. This identifier can be produced in several ways: a hash function applied to the URL and truncated to a fixed length, a sequential counter encoded in base62 (using a-z, A-Z, 0-9 to maximize density), or a random string generated and checked against existing entries to avoid collisions. The identifier becomes the path component of the short URL. The service stores the mapping in a key-value database -- something like Redis, DynamoDB, or a simple relational table -- where the key is the short code and the value is the original URL. Lookups happen in constant time regardless of how many URLs the service has stored.
URL shorteners became popular in the era of character-limited platforms, most notably Twitter's 140-character constraint. But their utility goes beyond saving characters. Marketers use them to track click-through rates across campaigns. Developers use them to create clean, shareable links for API documentation and support tickets. Print media uses them because nobody is going to type a 150-character URL from a magazine advertisement. The trade-off is that you are adding a dependency -- if the shortening service goes down or shuts down entirely, every short link it ever created stops working. That is the link rot problem, and it is a real concern for any link you expect to last longer than a few months.