How Tiny URLs Work
I was reading an article by Tom Critchlow on why we shouldn’t use tiny urls in newspapers. All good stuff, but this got me thinking about how the tinyURL system works? TinyURLs are useful when referring people to sites on Twitter.
Clearly we require a mapping which takes a URL and maps it to a unique but shorter URL. Hash tables do this; there is an input and a method of encoding which generates the tinyURL.
What could be used? MD5 produces a code that is 32 characters still too long and a usability minefield. Other MD codings are available and MD2 produces a shorter code but still looks unwieldy.
If you are running a tinyURL service you really need only sequentially add links to a database as they come in. and you convert the text into a number of a large base.
We are all familiar with base 10, even if you have lost a few digits on your hands. Geeks are happy using Octal, base 8, or Hexadecimal, base 16.
When we run out of numbers we start using letters to stand for numbers. 10=A, 11=B, 12=C, 13=D, 14=E, 15=F. Large numbers become smaller because there are more choices of per position and each additional place goes up a power of the base.
In base 36, we use the number and the 26 lower case letters.
In 5 characters we can store, 36 * 36 *36 *36 *36 web sites = 60,466,176 web sites. A tiny URL service will just take a URL and store it in the database with the base 36 id. When a link is click the URL it 301 redirects the link from the tiny URL to the URL stored in the database.The next URL to be added just increments the base 36 id. Looking at the headers we can see this is indeed the case. A 301 redirect to the site. Anyone could set up their own tinyURL service quite easily with a php script. This would allow you to create your own tinyURL service for Twitter although if you have a long domain it is less useful but it would give users some idea about where the link was going to.
tinyurl.com/2 is about unicycling!
Snooker Dining Tables available here
Service Reminder Stickers
t-shirt personalizzate


![Validate my RSS feed [Valid RSS]](http://www.seothegame.com/wp-content/uploads/2008/11/valid-rss.png)
Hey Carl,
Great post. Any idea where I could get a “Tiny URL” on my own that would also enable me to track clics … ?
Cheers
B.