How Do I Decode a Discord Snowflake Id

Published
Length
3 min read

Luis Felipe Dias

All posts

You decode a Discord ID by shifting its 64-bit integer right by 22 bits. Then you add the custom epoch value to get the exact creation timestamp. Many engineers ask how do i decode a discord snowflake id during incident reviews. Chat apps generate these unique 64-bit numbers for every user, message, and channel. Reading the raw bits reveals when an event occurred down to the millisecond. Teams and AI agents use this timestamp data to order events and audit logs. How do i decode a discord snow

Microsoft Entra ID (Azure AD) + Snowflake Access Control: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You decode a Discord ID by shifting its 64-bit integer right by 22 bits. Then you add the custom epoch value to get the exact creation timestamp.

Many engineers ask how do i decode a discord snowflake id during incident reviews. Chat apps generate these unique 64-bit numbers for every user, message, and channel. Reading the raw bits reveals when an event occurred down to the millisecond. Teams and AI agents use this timestamp data to order events and audit logs.

How do i decode a discord snowflake id in practice

The ID format splits a 64-bit number into four distinct parts. The first 42 bits store the time in milliseconds since a custom start date. The platform sets this start date to the first second of the year 2015. The next five bits identify the internal worker that made the number. Another five bits identify the internal process that ran the task. The final 12 bits store a counter for IDs made in that same millisecond.

To read the time, convert the text string into a 64-bit integer first. Standard 32-bit math will break the number and give you the wrong date. Next, shift the binary bits to the right by 22 places. This step drops the worker, process, and counter bits from the end. Now add 1,420,070,400,000 to the result to account for the 2015 start date. You now have a standard Unix timestamp in milliseconds for your log tools.

Engineers and AI agents run this math to check account age and message order. Because the time sits in the highest bits, the IDs sort by time naturally. You do not need to look up a separate date column in your database. Your app can sort records by the ID column and get the right order. You can also mask lower bits to read the worker ID or counter value.

Security and operational tradeoffs in production

Chat bots and audit scripts often store these IDs inside production databases. Teams set up database roles and static keys so apps can read this data. Static roles control which table a bot or engineer can query at first. Still, a role cannot inspect individual queries once an active database session begins.

Microsoft Entra ID (Azure AD) + Snowflake Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

When an engineer or AI agent queries user tables, raw records return in full. Along with the public chat ID, the row often holds private user details. These fields might include emails, phone numbers, card numbers, or national IDs. A broad database role lets the active session read every column in that table by default.

Data masking rewrites matched fields in results so sensitive columns stay protected during queries. Teams also need query logs that show who ran each command in production. Without per-query checks, a compromised bot key or careless script can pull entire tables. Good operations pair database roles with query-level controls and field masking for active sessions.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can a decoded ID reveal a user IP address or location?

No, the 64-bit number only contains the creation time, worker numbers, and sequence counter. It never stores personal network data, user locations, or private account details.

Why do I get the wrong date when decoding in JavaScript?

Standard JavaScript numbers lose precision above 53 bits, which corrupts a 64-bit chat ID. You must convert the ID string into a BigInt type before shifting bits.

Can two messages share the exact same ID?

No, the worker bits, process bits, and 12-bit counter keep every single ID unique. Each process can generate 4,096 unique numbers within a single millisecond without any clash.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.