Developer4 min read

What is a UUID and How to Generate One

UUIDs are everywhere in modern software — database IDs, API keys, session tokens. Here is exactly what they are and how to generate them.

🔑

Generate a UUID instantly

Use our free UUID Generator — generates cryptographically random v4 UUIDs instantly.

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. It is represented as 32 hexadecimal digits displayed in 5 groups separated by hyphens.

550e8400-e29b-41d4-a716-446655440000
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

Where:
M = version number
N = variant

UUID versions explained

v1

Time-based

Generated from current timestamp and MAC address. Reveals when and where it was created.

v3

Name-based (MD5)

Generated from a namespace and name using MD5 hashing. Same input always produces same UUID.

v4

Random (most common)

Generated from random numbers. Most widely used. Virtually impossible to predict or collide.

v5

Name-based (SHA-1)

Like v3 but uses SHA-1 hashing. More secure than v3.

Generate UUID in JavaScript

// Modern browsers and Node.js 14.17+
crypto.randomUUID()
// "550e8400-e29b-41d4-a716-446655440000"

// Using uuid npm package
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"

Generate UUID in Python

import uuid

# Generate v4 UUID
str(uuid.uuid4())
# "550e8400-e29b-41d4-a716-446655440000"

# Generate v1 UUID
str(uuid.uuid1())

When to use UUIDs

  • Database primary keys — no need for auto-increment
  • API resource identifiers — /users/550e8400-e29b-41d4-a716-446655440000
  • Session tokens and request IDs
  • File names for uploaded files
  • Distributed systems where IDs must be unique across machines

Related Tools