desarrollo

What is a UUID and how to generate it

Learn what a UUID is, what it is for, and the difference between v4 and v7 formats.

Table of contents
  1. 01Introduction
  2. 02How is a UUID formed?
  3. 03UUID v4 vs UUID v7
  4. 04Tips for use
Programming code on a screen

Introduction

A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information in computer systems. Its main feature is that the probability of two generated UUIDs being identical is virtually zero.

Thanks to this property, UUIDs are used as primary keys in databases, session identifiers, file names, e-commerce orders and any system where you need an identifier that does not repeat.

How is a UUID formed?

A standard UUID is represented as 32 hexadecimal digits grouped into 5 blocks separated by hyphens, totalling 36 characters. For example:

  • 9ec14e0a-123b-4c5d-8e6f-4789a0b1c2d3
  • Version: the fourth block starts with the version number (v4) or letter (v4/v7).

UUID v4 vs UUID v7

UUID v4 is generated completely at random: the 122 information bits are random. It is the most widely used format and compatible with virtually all libraries on the market.

UUID v7 is newer and incorporates a timestamp in the first 48 bits. This makes them chronologically sortable, which is very useful for using them as database keys with better index performance.

Our UUID generation tool lets you create both formats, and several at a time, with a single click. Try it with the online UUID generator.

Tips for use

Use UUID v4 when you need maximum compatibility with older libraries. Use UUID v7 if you are storing it in large databases where temporal order matters. And remember: never use UUIDs as security secrets, as they are identifiers, not credentials.