The Tech Behind Spotify Codes: 23 Lines, 8 Heights, and Billions of Songs

Mar 19, 2026
#spotify #algorithm

Have you ever noticed those neat little soundwave-looking barcodes on Spotify that let you instantly share a song or a playlist? They are called Spotify Codes, and while they look like simple audio waveforms, they are actually a highly engineered, data-dense proprietary barcode system.

Before we dive into the technical details, you might want to check out a practical application: I’ve utilized Spotify Codes to create a tool for making a musical letter!

Instead of relying on standard QR codes, Spotify decided to create a visually appealing alternative that perfectly matches their brand identity. But how do they work under the hood? Let’s dive into the technical anatomy of a Spotify Code, the math behind its storage limits, and what might happen if Spotify ever runs out of space.

The Anatomy of a Spotify Code

At first glance, a Spotify Code looks like a random assortment of lines. However, if you look closely, you will realize it follows a very strict and precise structure:

  • 23 Vertical Lines (Bars): Every single Spotify Code consists of exactly 23 vertical bars.
  • 8 Distinct Heights: Each of these bars can be rendered at one of 8 different heights.

Because there are exactly 8 possible heights for each bar, the data is essentially encoded in an octal system (base-8).

The Role of the 23 Bars

Not all 23 bars carry song data. Just like standard barcodes or QR codes, a scanner needs reference points to understand the scale, orientation, and distortion of the image.

In a Spotify Code:

  • The first, middle (12th), and last (23rd) bars serve as synchronization markers and calibration references for the scanner.
  • This leaves exactly 20 bars dedicated to encoding the actual payload information.

How the Data is Encoded

If we have 20 data-carrying bars, each capable of 8 different heights, the total number of raw visual combinations is $8^{20}$, or $2^{60}$ (or roughly 1.15 quintillion combinations).

So, does a Spotify Code store exactly 60 bits of raw song data? Yes, but not all of it forms the song’s identifier.

To ensure that the code scans instantly, even in low light, at an angle, or if the user’s phone screen is cracked, Spotify uses Forward Error Correction (FEC) to make the codes remarkably resilient.

  1. Redundancy: Out of the 60 bits encoded visually, 15 bits are dedicated entirely to error correction.
  2. Payload: This leaves a 45-bit usable data payload.
  3. Media Reference: From this 45-bit payload, Spotify extracts a precise 37-bit media reference.

When you point your camera at a code, the Spotify app reads the heights, applies Gray code decoding to minimize read errors, runs the error correction algorithm, extracts the 37-bit media reference, and then queries Spotify’s backend servers to fetch the exact song, album, or user profile.

The Limit: How Many Songs Can Be Stored?

Since the core identifier is exactly 37 bits long, the absolute theoretical maximum number of unique media references Spotify can generate natively is:

$2^{37}$ = 137,438,953,472

That is approximately 137.4 billion unique combinations.

To put that into perspective, as of recent counts, Spotify’s catalog hosts a little over 100 million tracks. Even if you aggressively factor in user-generated playlists, albums, and user profiles that also get their own codes, they are barely scratching the surface of their 137.4 billion limit. Currently, they have used a tiny fraction of a percent of the available combinations.

Breaking the Limit: What Happens When They Run Out?

Even though 137.4 billion is a massive number, history in computer science tells us that artificial integer limits are always meant to be broken (remember the Y2K bug or IPv4 address exhaustion?).

What happens if, decades from now, the sheer amount of generated content pushes past this theoretical limit? Because Spotify engineered this system from the ground up, they have several highly technical escape hatches they could use:

  1. Utilizing the Unused Bits (Versioning): Remember that the decoded payload is 45 bits, but the primary media reference only uses 37 bits. This leaves 8 bits unaccounted for. These 8 bits could simply be acting as a reserved version control flag. If Spotify increments a version bit, they instantly unlock an entirely new set of 137.4 billion combinations. With 8 bits of versioning headroom, the actual upper bound of the current system is $2^{45}$ (over 35 trillion items).
  2. Adding More Heights (Hexadecimal Upgrades): If they upgraded the scanner software (and assumed phone cameras were high-resolution enough) to reliably recognize 16 distinct heights instead of 8, the code would transition from an octal (base-8) system to a hexadecimal (base-16) system. This would double the bit capacity per bar, instantly quadrillion-sizing their limit without fundamentally changing the physical layout or width of the code.
  3. Adding More Bars: While it would change the visual aesthetics and require a wider barcode layout, increasing the code from 23 bars to 25 or 27 bars would exponentially increase the storage limit.
  4. Database Pruning and Recycling: A vast majority of user-generated playlists are temporary, deleted, or abandoned. Spotify could eventually prune their backend database and recycle the 37-bit references from dead links, ensuring the active pool of codes remains well under the 137 billion mark.

Conclusion

Spotify Codes are a masterclass in blending graphic design with rigorous computer science. By cleverly utilizing an octal visual system with 23 vertical lines and 8 distinct heights, Spotify created a scannable tag that looks like a friendly audio waveform but functions exactly like a high-density, error-correcting database key.

With a robust 37-bit identifier providing over 137 billion combinations natively, it is safe to say we won’t be running out of Spotify Codes anytime soon. And if we ever do, the engineers left themselves plenty of technical headroom to seamlessly scale up to trillions.