Generate ObjectID
MongoDB’s native 12-byte document key rendered as 24 hex characters — 4 bytes of seconds since the Unix epoch, 5 bytes of random material, and a 3-byte counter that increments per generated ID.
Generated · 0 IDs
Options
This ID
Collision
Within one generator the 24-bit counter increments, so it never repeats within a second. Separate generators also need the same 5 random identity bytes before counters can line up.
Validate and parse ObjectID
Paste an ID
About ObjectID
Use when: you are interoperating with MongoDB or want a compact hex ID with a built-in second-resolution timestamp.
Avoid when: you do not want a stable generator fingerprint inside the ID, or you need millisecond timestamp precision.
How it is generated
A MongoDB ObjectID is 12 bytes (96 bits) hex-encoded as 24 characters. The spec partitions those 12 bytes into three fields: a 4-byte seconds-since-epoch timestamp, a 5-byte process-stable random value, and a 3-byte counter.
In this browser implementation the 5-byte random field comes from crypto.getRandomValues — shared within a batch and re-randomized on each Regenerate — replacing the original spec's machine + pid combination. The design idea is the same: two ObjectIDs from the same tab never collide because the counter increments; two from different tabs are vanishingly unlikely to collide because the random middle field differs.
Seconds-precision timestamp means same-second ordering relies entirely on the counter.
- 01 Take the current Unix-seconds time as 4 big-endian bytes for bytes 0–3.
- 02 Place the 5-byte random value into bytes 4–8 (from crypto.getRandomValues; shared within a batch, re-randomized on each Regenerate).
- 03 Place the 3-byte counter into bytes 9–11; start counter at a random 24-bit value and increment by 1 per ID, wrap at 2²⁴.
- 04 Hex-encode the 12 bytes (lowercase by spec, the UI offers uppercase display).
Source bytes (12 = 96 bits):
bytes 0..3 32-bit big-endian Unix-seconds timestamp
bytes 4..8 5-byte random (per batch, re-rolled on Regenerate)
bytes 9..11 3-byte big-endian counter (random start, ++ per ID,
wraps at 2^24 = 16,777,216 IDs)
Encoded form (24 chars):
the 12 bytes are hex-encoded — each byte becomes two hex chars.
example: 507f1f77bcf86cd799439011
└──────┘└────────┘└────┘
ts (8) random (10) ctr (6)
Alphabet: 0-9 a-f (hex, lowercase by spec; upper available as display) All of this runs in your browser. Random bytes come from crypto.getRandomValues, timestamps come from the system clock, and nothing about the generated ID leaves the tab.