Last updated
How to Decode an Instagram Shortcode to a Date
Every Instagram post URL contains a shortcode — the alphanumeric string after /p/ in the URL. This shortcode is a Base64-encoded representation of Instagram's internal numeric media ID, which contains an embedded creation timestamp. By decoding the shortcode, you can determine exactly when any Instagram post was published. The TechConverter.me decoder automates this process, but this guide also explains the algorithm so you can implement it yourself.
Code Examples
JavaScript Implementation
function decodeInstagramShortcode(shortcode) {
// Instagram's Base64 alphabet
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
// Convert shortcode to media ID
let mediaId = 0n;
for (let char of shortcode) {
mediaId = mediaId * 64n + BigInt(alphabet.indexOf(char));
}
// Extract timestamp (right shift by 22 bits)
const timestamp = Number(mediaId >> 22n);
// Convert to date
const date = new Date(timestamp * 1000);
return {
shortcode: shortcode,
mediaId: mediaId.toString(),
timestamp: timestamp,
date: date.toUTCString()
};
}
// Example usage
const result = decodeInstagramShortcode('CwkxyiVP2MU');
console.log(result);
// Output: { shortcode: 'CwkxyiVP2MU', mediaId: '3165871364981502292',
// timestamp: 1690123456, date: 'Sun Jul 23 2023 12:34:16 GMT' }
Python Implementation
from datetime import datetime
def decode_instagram_shortcode(shortcode):
"""Decode Instagram shortcode to date"""
# Instagram's Base64 alphabet
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
# Convert shortcode to media ID
media_id = 0
for char in shortcode:
media_id = media_id * 64 + alphabet.index(char)
# Extract timestamp (right shift by 22 bits)
timestamp = media_id >> 22
# Convert to date
date = datetime.fromtimestamp(timestamp)
return {
'shortcode': shortcode,
'media_id': media_id,
'timestamp': timestamp,
'date': date.strftime('%Y-%m-%d %H:%M:%S UTC')
}
# Example usage
result = decode_instagram_shortcode('CwkxyiVP2MU')
print(result)
# Output: {'shortcode': 'CwkxyiVP2MU', 'media_id': 3165871364981502292,
# 'timestamp': 1690123456, 'date': '2023-07-23 12:34:16 UTC'}
Try It Online
Common Examples
| Shortcode | Media ID | Creation Date |
|---|---|---|
CwkxyiVP2MU |
3165871364981502292 | July 23, 2023 |
C5pqrXYZ123 |
3245678901234567890 | January 15, 2024 |
DAbcdefGHIJ |
3312456789012345678 | June 10, 2024 |
Understanding the Format
Instagram shortcodes are 11 characters long and use a custom Base64 alphabet. The encoded media ID contains:
- First 42 bits: Unix timestamp (seconds since epoch)
- Remaining bits: Server ID and sequence number
Pro Tip
Instagram reels and posts use the same shortcode format. The decoding process works for both!
Frequently Asked Questions
Can I decode Instagram reels the same way?
Yes! Instagram reels use the same shortcode format as regular posts. The decoding process is identical.
Why would I need to decode Instagram shortcodes?
Common use cases include: data analysis, content research, timestamp verification, archiving, and understanding post chronology.
Is this method accurate?
Yes, the timestamp is encoded directly in the media ID by Instagram's servers. The decoded date is accurate to the second.
Can I decode private posts?
Yes, as long as you have the shortcode from the URL. The shortcode itself contains the timestamp regardless of privacy settings.
Related Tools
Example 2: The Instagram Base64 Alphabet
Instagram uses a custom Base64 alphabet to encode shortcodes. Each character maps to a 6-bit value:
Instagram alphabet:
A-Z = 0-25
a-z = 26-51
0-9 = 52-61
- = 62
_ = 63
Standard Base64 uses + and / for positions 62 and 63.
Instagram uses - and _ instead (URL-safe variant).
Example 3: Decoding a Shortcode to a Numeric ID in Python
INSTAGRAM_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
def decode_shortcode(shortcode):
"""Convert an Instagram shortcode to its numeric media ID."""
n = 0
for char in shortcode:
n = n * 64 + INSTAGRAM_ALPHABET.index(char)
return n
# Example:
media_id = decode_shortcode("CxYz123abcD")
print(media_id) # e.g., 3012345678901234567
Frequently Asked Questions
To decode an Instagram shortcode: 1) Convert from Base64 to numeric ID, 2) Right shift by 22 bits, 3) Convert timestamp to date. You can use online tools or code in Python/JavaScript.
An Instagram shortcode is the unique identifier in Instagram URLs (e.g., CwkxyiVP2MU). It encodes the post ID, which contains the creation timestamp.