MongoDB ObjectID decoder

A MongoDB ObjectID is 12 bytes (24 hex characters): a 4-byte unix-seconds timestamp, a 5-byte random value generated per-process, and a 3-byte incrementing counter.

12 bytes · hex
objectid (24 hex)-
decoded-
created at
-
unix seconds
-
relative
-
timestamp hex
-
random hex
-
counter
-
layout12 bytes

ObjectID structure:

4 bytes · big-endian unix seconds (good until 2106).

5 bytes · per-process random value (stable within a driver instance).

3 bytes · incrementing counter (random initial value per process).

A 5-byte random value isn't a machine ID anymore - the modern spec replaced the old machine+PID layout.

-

Related decoders