In software development, we constantly need unique identifiers. Whether you're building a database, a distributed system, or an API, you'll inevitably come across the term UUID. Yet behind those four letters lies a standard that is sometimes misunderstood. So, what is a UUID exactly? How do you generate a UUID in Python? Can you decode a UUID? What's the difference between UUID v4 and a UUID v5 generator?
In this article, I’ll answer those questions with concrete examples, code snippets, and a free online tool that makes your life easier. I’ve also included practical tips gathered from the field, because I use these identifiers every week myself in Python and Node.js projects.
What is a UUID? A simple definition and a concrete example
UUID stands for Universally Unique Identifier. It’s a 128‑bit number (16 bytes) classically represented as a 36‑character string, arranged in five groups separated by hyphens. The most common UUID example looks like this:
550e8400-e29b-41d4-a716-446655440000
This identifier is designed to be globally unique: the probability of generating the same one twice is so low that it’s considered zero in practice. That’s why UUIDs are used as primary keys in databases, as session identifiers, as temporary file names, and so on.
The main advantage of a UUID over a simple auto‑incremented integer is its ability to be generated in a decentralized manner, without coordination between machines in a cluster.
The different UUID versions (v1, v4, v5) explained simply
Not all UUIDs are created equal. The RFC 4122 standard defines several versions, each with a different generation mechanism. Here are the three most common:
- UUID v1 — based on timestamp and the machine’s MAC address. It allows you to decode a UUID to retrieve the exact moment it was created. In return, it exposes network information.
- UUID v4 — generated from random numbers. It’s the simplest and most widely used. It offers 122 bits of effective entropy, making it unpredictable.
- UUID v5 — deterministic, based on a SHA‑1 hash of a namespace and a name. You use it when you want to always obtain the same UUID for the same input, which is useful for creating reproducible identifiers (e.g., from a URL or an email address).
Python uuid generator: how to generate a UUID in Python
Python includes the uuid module in its standard library, which makes generation trivial. Here are three snippets that cover the most requested versions.
Generate a UUID v4 (random) in Python
import uuid
id = uuid.uuid4()
print(id) # Example: 4ec27c8c-6c08-4d26-92b3-9d2e9c6f4ed2
This is the method to use for most cases: session identifiers, primary keys, etc.
Generate a UUID v5 (deterministic) in Python
For a reproducible UUID from a string, you pass through uuid.uuid5(). You must give it a namespace (among the predefined DNS, URL, OID, X500) and a name:
import uuid
namespace = uuid.NAMESPACE_DNS
identifier = uuid.uuid5(namespace, "www.example.com")
print(identifier) # Always the same UUID for this name
This approach is ideal for turning email addresses or article slugs into stable, unique identifiers.
Decoding a UUID v1: extracting the timestamp and node
Contrary to what some believe, uuid decode isn’t magic — but only UUID v1 (and to some extent v2) contain exploitable data. UUID v4 and v5 are purely random or hashed, so they cannot be deciphered.
Take a UUID v1 like this one:
6ba7b810-9dad-11d1-80b4-00c04fd430c8
When you run it through a decoder, you get:
- Timestamp: corresponds to the number of 100‑nanosecond intervals since October 15, 1582. Converted to a readable date, it gives the exact moment of creation.
- Node: the MAC address of the network card (here 00:c0:4f:d4:30:c8).
Our online UUID / ULID generator includes a Decode tab that does this automatically. You paste a UUID, it detects the version and, if it’s a v1, displays the timestamp and node. It also works for ULID, a modern sortable format.
Why prefer ULID over UUID in some cases?
ULID (Universally Unique Lexicographically Sortable Identifier) is a UUID alternative that is gaining ground. Unlike UUID v4, they are sortable in creation order, because they start with a timestamp encoded in base32. This is crucial for database indexes, because an index on a sorted key is far more performant than an index on a random key.
Our online tool generates both UUIDs and ULIDs with a single click. You can even produce them in batches and copy them as JSON or CSV.
Free UUID / ULID generator: quick start guide
To save you from writing a Python script every time, the DevToolbox tool provides an interface with four tabs:
- Generate: creates one or more UUIDs (v1, v4, v5) or ULIDs, with format options (hyphens, uppercase).
- Validate: paste any string to find out if it’s a valid UUID, its version, or a ULID.
- Decode: for UUID v1 and ULID, extracts the timestamp and the corresponding date.
- Compare: side‑by‑side comparison table of UUID vs ULID (length, sorting, encoding, use cases).
Everything runs in your browser, nothing leaves your machine. You can also copy code snippets for JavaScript, Go, and SQL directly from the tool.
Integration with other DevToolbox tools
Once your UUID is generated, you can combine it with other platform utilities:
- JSON Formatter — to cleanly insert your UUID into a JSON structure.
- JWT Decoder — because many JWT tokens carry UUIDs as session identifiers.
- Base64 Encoder — if you need to encode your UUID for an HTTP header.
- Regex Tester — to validate your own UUID patterns in business logic.
FAQ – frequently asked questions about UUIDs
What exactly is a UUID?
It’s a 128‑bit standardized identifier, designed to be unique without central coordination. It is represented as xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
How do I generate a UUID in Python?
With import uuid then uuid.uuid4() for a random UUID, or uuid.uuid5(ns, name) for a deterministic UUID.
Can a UUID be decoded?
Yes, for UUID v1: you can extract the timestamp and MAC address. UUID v4 and v5 do not contain exploitable information.
What’s the difference between UUID v4 and v5?
UUID v4 is random; each call produces a different identifier. UUID v5 is deterministic: for the same namespace and name, it always returns the same UUID.
Can I use ULID instead of UUID?
Yes, especially if you need chronological sorting. ULID is shorter (26 characters) and lexicographically sortable.