📸 How to Decode Instagram Shortcode to Date

Complete step-by-step guide with code examples

What is an Instagram Shortcode?

An Instagram shortcode is the unique identifier you see in Instagram URLs. For example, in https://instagram.com/p/CwkxyiVP2MU/, the shortcode is CwkxyiVP2MU.

This shortcode encodes the post's media ID, which contains the creation timestamp. By decoding it, you can find out exactly when a post or reel was created.

Step-by-Step Decoding Process

1 Extract the Shortcode

Get the shortcode from the Instagram URL. It's the part after /p/ or /reel/.

Example:

URL: https://instagram.com/p/CwkxyiVP2MU/

Shortcode: CwkxyiVP2MU

2 Decode from Base64

Instagram uses a custom Base64 alphabet. Convert the shortcode to a numeric media ID using this alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_

3
Extract Timestamp

Right shift the media ID by 22 bits to extract the Unix timestamp (in seconds).

4
Convert to Date

Convert the Unix timestamp to a human-readable date and time.

Code Examples

JavaScript Implementation

JavaScript
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

Python
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

Decode Instagram Shortcode

Shortcode
Media ID
📅 Creation Date
⏱️ Unix Timestamp

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:

💡 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