How Discord Snowflake Bit Shifting Encodes Timestamps
When building a Discord bot or moderating a large community, the Discord API often gives you an 18-digit ID like 175928847299117063 without a separate creation date field. Every Discord user, message, channel, and server ID actually stores its exact millisecond creation time inside its upper binary bits.
Inside the 64-Bit Discord Snowflake Layout
Discord adapts Twitter's Snowflake format into an unsigned 64-bit integer split into four bit segments. You can verify this structure in the Discord Developer Reference.
| Bit Range | Size | Purpose |
|---|---|---|
| Bits 63 to 22 | 42 bits | Milliseconds elapsed since Discord Epoch (2015-01-01T00:00:00Z) |
| Bits 21 to 17 | 5 bits | Internal Worker ID (0 to 31) |
| Bits 16 to 12 | 5 bits | Internal Process ID (0 to 31) |
| Bits 11 to 0 | 12 bits | Increment counter per process per millisecond (0 to 4095) |
The Discord Epoch Constant: 1420070400000
Instead of starting at 1970, Discord begins counting at January 1, 2015 at 00:00:00.000 UTC. That date equals 1,420,070,400,000 Unix milliseconds. Starting at 2015 lets 41 timestamp bits last roughly 69 years from 2015 (until the year 2084) before rolling over.
Code Example: Decode and Generate Snowflakes in Python
Shift the integer right by 22 bits to discard the worker, process, and increment bits, then add 1420070400000:
from datetime import datetime, timezone
DISCORD_EPOCH_MS = 1420070400000
snowflake_id = 175928847299117063
timestamp_ms = (snowflake_id >> 22) + DISCORD_EPOCH_MS
created_at = datetime.fromtimestamp(timestamp_ms / 1000, tz=timezone.utc)
print(created_at.isoformat()) # 2016-04-30T11:19:17.007000+00:00