Back to blog

How a short code is generated

The difference between sequential and random codes, why the Base58 set drops confusable glyphs, how large the 7-character space is, and how the rare collision is handled.

In linkpado.com/xY3kP9q, how is the xY3kP9q part — the short code — chosen? It looks like a few characters thrown together, but generating that string involves several decisions: predictability, coordination between servers, and what to do on a collision. This post walks through how linkpado makes a code, one decision at a time.

Count in order, or draw at random?

There are two broad ways to generate codes.

The sequential approach numbers each link 1, 2, 3… as it's created and converts that number into short characters. It's simple to build, and codes can never overlap. But two problems follow.

First, the next link is guessable. If someone receives linkpado.com/0001, they can try 0002 and 0003 too, and peek at where other people's links lead. The number also reveals roughly how many links have been created so far.

Second, servers have to agree on the count. In a distributed setup, several servers create links at once, and for all of them to share the same "next number" you need a synchronization mechanism — a central counter or a lock. That coordination becomes a bottleneck as traffic grows.

The random approach draws a few characters at random from a fixed set each time. Because nothing is being counted, the next link is hard to guess, and servers never need to agree on whose turn is next. Each server draws on its own and only has to handle the rare overlap. linkpado uses this random approach.

Base58: why drop some characters

If you're drawing at random, you have to decide which characters to draw from. linkpado uses the Base58 set. As the name says, it has 58 characters: the full set of uppercase letters, lowercase letters, and digits (62 in all), minus four that are easy to confuse.

The dropped characters are:

  • The digit 0 and the capital O — nearly identical in shape.
  • The digit 1, the lowercase l, and the capital I — indistinguishable in many fonts.

The reason to drop them is for when a person reads and copies a code by eye. Picture writing a code on paper, reading it aloud over the phone, or typing it from a screen. A code mixing l and 1 is easy to mistype, and a single wrong character sends you somewhere else or opens nothing at all. Base58 removes that chance from the start. For the same reason, Base58 has long been used in places like Bitcoin addresses.

How many combinations does 7 characters give?

linkpado's default code is 7 characters long. Each position can be any of 58 characters, so the total number of combinations is 58 multiplied by itself seven times.

58 × 58 × 58 × 58 × 58 × 58 × 58 ≈ 2,207,984,167,552

That's over two trillion. Why does the size matter? When you draw codes at random, an already-used code can in theory come up again — but with this many possibilities, the odds of that are tiny. Even with millions of links already created, a freshly drawn 7-character code is very unlikely to match one of them. When the space is wide enough, you don't need a sequential counter to guarantee "no overlap"; in practice, overlaps barely occur.

What happens on the rare collision

Saying overlaps "barely" occur means they can occur, just very rarely. linkpado handles that uncommon case like this.

A code is stored in the database as a unique key. Try to store the same code twice and the database refuses. So if storing a new code is rejected, that's the signal the code is already in use. At that point the service draws a fresh code and tries the store again. This retry is capped at a small number of attempts.

What's nice about this is that there's no need to check before creating a code, and no coordination between servers. A server just draws, attempts the store, and only redraws when it's rejected. Because collisions are so rare, the retry almost never runs, and when it does, a single redraw usually settles it.

Why a strong random source matters

The last piece is how the "random" is produced. linkpado draws its codes from a cryptographically secure random generator. Unlike ordinary randomness, this kind is designed so that seeing the values produced so far gives no practical way to predict the next one.

For codes, that translates directly into safety. Even if someone studies the link they received, xY3kP9q, to work out someone else's link, they have nothing to go on for what the next code will be. A sequential scheme lets you try adjacent numbers, but a code drawn securely from a space of two trillion is far too much to brute-force by guessing.

In short, a single linkpado code carries four decisions at once: the random approach that blocks guessing, the Base58 set that drops confusable glyphs so people can read it, the roomy 7-character space that keeps collisions rare, and the random generator that draws within it safely. You never need to think about any of this day to day, but that's how one short address comes to be. If you want a more readable ending, Pro lets you set a custom path of 3 to 32 lowercase letters, digits, and hyphens. To make a link yourself, you can try it from the home page.