Snowflake ID Decoder
A Snowflake ID looks like a long random number, but it is a 64-bit value with fields in it. The high bits hold a timestamp, and the low bits hold a machine and a sequence number, so one ID in a log tells you when a row was created and which worker created it. The catch is that each system picks its own epoch and bit layout, so the same number decodes to a different date under each one. This decoder knows the published layouts for Twitter / X, Discord, Instagram, Sonyflake and Mastodon, and you can enter a custom epoch, time unit and field layout for your own generator. Paste IDs, one per line, in decimal or 0x hex, or paste a link or a Discord mention that ends in an ID. For each ID, you get the creation time, each field, the hex value and the bits split by field. If the date falls in the future, the tool tells you which presets give a possible date instead. Enter dates and it works in reverse, giving the lowest ID for each moment and a PostgreSQL or MySQL query on the primary key, so you can select a time range through the index without a created_at column. All arithmetic uses BigInt, so no digits are lost, and the tool warns you about IDs that a JavaScript number would round. The results were compared with bit operations on PostgreSQL and MySQL and with the worked examples published by Discord and Twitter. Everything runs in your browser, so no IDs are uploaded.
Do more than snowflake id decoder — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Choose the system that generated the IDs, or choose Custom and enter the epoch, time unit and bit layout.
- Paste IDs, links or dates, one per line, and enter the table and column for the generated SQL.
- Click Decode, then read the time and fields of each ID or copy the PostgreSQL or MySQL query. With two or more dates, the query covers the earliest to the latest.
Frequently asked questions
How do I get the timestamp from a Snowflake ID?
Shift the ID right to drop the bits below the time field, add the epoch, and read the result as Unix milliseconds. Discord keeps 22 bits below the time field and uses the epoch 1420070400000, so 175928847299117063 >> 22 is 41944705796, and adding the epoch gives 1462015105796, which is 2016-04-30T11:18:25.796Z. In PostgreSQL, the same calculation is SELECT to_timestamp(((175928847299117063::bigint >> 22) + 1420070400000) / 1000.0). The time comes from the clock of the worker that generated the ID, so IDs from different workers can be slightly out of order.
Why does my Snowflake ID change in JavaScript?
A JavaScript number is a 64-bit float with 53 bits of precision, and current Snowflake IDs are larger than 2^53, so JSON.parse rounds them. The ID 1541815603606036480 can come back with different last digits, and a lookup then fails or finds another row. That is why APIs such as Discord return IDs as strings, and why Twitter added an id_str field. Keep IDs as strings in JSON, or read them as BigInt. On the database side, store them in a bigint column, because a double precision column rounds them the same way.
Should I use Snowflake IDs or UUIDv7 as a primary key?
Both sort by time, which keeps inserts near the end of a B-tree index. A Snowflake ID is 8 bytes, fits a bigint column and makes smaller indexes, but each generator needs a unique worker number, and that takes coordination. A UUIDv7 is 16 bytes and needs no coordination, because its random bits avoid collisions, and PostgreSQL 18 can generate one with uuidv7(). If you can assign worker numbers and want compact keys, Snowflake works well. If you want IDs from any client with no setup, use UUIDv7. To test these queries against your own tables in a GUI, try Chat2DB: download it at chat2db.ai/download or open app.chat2db.ai.
