Skip to content
shortuuid

Private by design: runs in your browser, nothing is sent anywhere

Short UUID converter

Write any UUID in 22 characters instead of 36, as Base62, Base58 or Base64url, and turn short IDs back into the exact UUID. Paste one or a whole list.

62 chars: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

UUIDs or short IDs, one per line

Result

Thinking of cutting IDs shorter still? Check the collision odds first.8 Base62 characters hold 47.6 bits: 20 million of them have a 60% chance of a duplicate.Collision calculator

Three ways to write 128 bits

EncodingCharactersLengthBits per charSorts like the UUIDGood for
Base620-9 A-Z a-z225.95YesLetters and digits only: safe in URLs, file names and identifiers, double-click selects the whole ID.
Base58Base62 minus 0 O I l225.86YesNothing that looks alike, for IDs people read aloud or type in.
Base64urlA-Z a-z 0-9 - _226.00NoStandard (RFC 4648) and built into most languages, but - and _ are out of ASCII order and can look odd at the ends of an ID.
Hex (UUID)0-9 a-f, plus 4 hyphens364.00YesThe standard form, for comparison.

All three need 22 characters, because 128 bits ÷ log₂(alphabet size) is 21.5 for Base62, 21.9 for Base58 and 21.3 for Base64url. The UUID 01a1bb07-9a00-7c3d-9f1a-6b2d4e8c0a17 is 034u0i5NnXmfJTzCqD24Pv, 1CgqRXNt3k857DzMnp4uk2 and AaG7B5oAfD2fGmstTowKFw.

How the conversion works

Base62 and Base58 treat the UUID as one 128-bit number and write it in base 62 or 58: divide by the base, the remainder picks the last character, repeat. The number is too big for a JavaScript Number, which is exact only up to 2⁵³, so the code uses BigInt. Padding to 22 characters with the alphabet's zero digit keeps every ID the same length, and since both alphabets are in ASCII order, short IDs then sort exactly like the UUIDs they encode. That matters for v7 UUIDs, which sort by time.

Base64url is different: RFC 4648 encodes the 16 bytes, 6 bits at a time from the left, and the last character carries the final 2 bits. That's why it can't be computed with the divide-and-remainder loop, and why its IDs don't sort like the UUIDs. This is the code the code examples run, in JavaScript:

const B62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

function encode(uuid, alphabet) {
  let n = BigInt("0x" + uuid.replace(/-/g, ""));
  const base = BigInt(alphabet.length);
  let s = "";
  while (n > 0n) {
    s = alphabet[Number(n % base)] + s;
    n /= base;
  }
  return s.padStart(22, alphabet[0]); // fixed length, so short IDs sort like the UUIDs
}

function decode(short, alphabet) {
  let n = 0n;
  for (const ch of short) {
    const d = alphabet.indexOf(ch);
    if (d < 0) throw new Error(`not in the alphabet: ${ch}`);
    n = n * BigInt(alphabet.length) + BigInt(d);
  }
  if (n >> 128n) throw new Error("more than 128 bits: not a UUID");
  return hyphenate(n.toString(16).padStart(32, "0"));
}

const hyphenate = (h) => `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;

// Base64url encodes the 16 bytes (RFC 4648), not the number, so it needs no BigInt.
const toBase64url = (uuid) => Buffer.from(uuid.replace(/-/g, ""), "hex").toString("base64url");
const fromBase64url = (s) => hyphenate(Buffer.from(s, "base64url").toString("hex"));

const id = "01a1bb07-9a00-7c3d-9f1a-6b2d4e8c0a17";
console.log(encode(id, B62));
console.log(encode(id, B58));
console.log(toBase64url(id));
console.log(decode(encode(id, B62), B62));
if (fromBase64url(toBase64url(id)) !== id) throw new Error("Base64url round trip failed");

Short in the URL, 16 bytes in the database

Short IDs are for places people see: URLs, links, file names, support tickets. In the database, keep the UUID in a native 16-byte type: uuid in PostgreSQL, BINARY(16) in MySQL, uniqueidentifier in SQL Server. Decode the short ID where the request comes in and query with the UUID. A VARCHAR(22) column takes more space than 16 bytes, its comparisons depend on the column's collation (a case-insensitive one would treat a and A as the same digit), and every other system that reads the table has to know your alphabet.

And don't shorten an ID by cutting characters off. The first characters of a short v7 UUID are its timestamp: IDs made within the same few milliseconds share their first 8 characters, so cutting to 8 turns every burst of traffic into duplicates. Even from a random UUID, 8 Base62 characters are only 47.6 bits. If you need a really short ID, generate a random one of that length and check the odds in the collision calculator.

Frequently asked questions

Does it work with both v4 and v7 UUIDs?+

Yes, and with every other version. The conversion works on the UUID's 128 bits as one number and doesn't care what they mean, so any UUID converts and comes back exactly. Base62 and Base58 short IDs of v7 UUIDs even keep their time order.

Is a short UUID less unique than the full one?+

No. It's the same 128 bits written with more symbols per character, so 36 characters become 22. Nothing is lost: a v4 UUID still has 122 random bits, and the short ID decodes back to the exact UUID. Uniqueness only drops if you cut characters off, which is a different ID with far fewer bits (see the collision calculator).

Why does my decoder reject a Base64url short ID?+

Some Base64 decoders insist on = padding, so that the length is a multiple of 4. A UUID in Base64url is 22 characters, so add two: in Python, base64.urlsafe_b64decode(s + "=" * (-len(s) % 4)). Base62 and Base58 never use padding; they're numbers, not byte groups.

Why do other Base58 tools give me 21 characters?+

Libraries built for Bitcoin, like bs58, write each leading zero byte as a 1 and don't pad otherwise, so about 1 UUID in 30 comes out at 21 characters (or fewer). This tool always pads to 22 so every ID has the same length and sorts like the UUID. The catch: bs58 reads a leading 1 as an extra zero byte and decodes those IDs to 17 bytes. Use one convention on both sides, or decode with the tool or code examples here.

Why doesn't Python's shortuuid library give the same result?+

shortuuid uses its own 57-character alphabet (no 0, 1, I, O or l), so its 22-character IDs are a different encoding of the same UUID. Both are valid; just decode with the library that encoded.

Is Base62 always 0-9, A-Z, a-z?+

No: there's no standard Base62 alphabet. This tool uses 0-9A-Za-z, the order used by GMP and most libraries, which also keeps short IDs sorting like the UUIDs because it's in ASCII order. Some libraries use 0-9a-zA-Z instead, which gives different strings for the same UUID.

Is anything sent to a server?+

No. The conversion and the calculations run in your browser, and nothing you paste is uploaded or stored.