Una mujer sonriente con auriculares escucha música mientras usa su teléfono móvil en un entorno al aire libre.

Spotify and maths: here's the formula for its music recommendations

  • 9 April 2025
  • 6 minutos
  • Blog

Who hasn't had the feeling that platforms like Spotify identify your musical tastes with an almost eerie precision? Or that it seems to know exactly which artist or song you want to listen to at any given moment, that almost everything it seems to recommend makes sense to you?

For many of its more than 200 million users, there is no better example of this than "Weekly Discovery", a playlist that automatically renews itself every Monday, offering them 30 new tracks every week tailored to their preferences, tastes and even moods.

The most surprising thing is that, alongside familiar songs, it often includes offerings from artists completely new to the listener, and still manages to hit the nail on the head. Far from being a coincidence, this ability is based on sophisticated mathematical algorithms that learn from the individual and collective behaviour of millions of people around the world. It's not magic, it's mathematics.

Music personalisation on a grand scale

Spotify currently has a huge user base (over 500 million active users) and a catalogue of tens of millions of songs. With so much music available, the challenge is to make it easy for everyone to discover songs they will like.

This is where the recommendation system comes into play: a series of machine learning algorithms that personalise the music experience. Every time a song is listened to or saved, that information feeds the algorithm. In fact, every action (playing a track, marking "like", adding to a playlist or even passing on a song after a few seconds) is recorded as part of each user's profile on this platform.

From here, Spotify can use complex mathematical models to anticipate quite accurately what music each user will like, so that they spend more time engaged with the platform. To achieve this, it combines two main approaches: collaborative filtering and content-based filtering.

Collaborative filtering: the wisdom of the crowd

Collaborative filtering is the classic method of many employed by many content streaming platforms (Netflix, Amazon, etc.), and at Spotify it forms the heart of personalised lists like Weekly Discovery, which users receive in their inbox every Friday.

The idea is simple: if other people with similar tastes to a particular user enjoy a certain artist or song that that user has not yet heard, there is a good chance that they will also like it. In this way, the system analyses the listening habits of all users, matching them with "neighbours" with similar preferences.

For example, if User A and User B have many favourite songs in common, but A has discovered a band that B does not know, the algorithm can recommend that band to User B and vice versa. To achieve this on a massive scale, Spotify represents the relationship between users and songs in a huge data matrix, which in the case of this platform could be a table with 200 million rows (each row is a user) and 40 million columns (each column is a song).

Imagine a table with 200 million rows (each row is a user) and 40 million columns (each column is a song). This matrix is mostly empty, as no user can listen to all the songs, but the algorithm exploits it using linear algebra techniques. Specifically, Spotify applies a matrix factorisation (a way of decomposing the matrix) to extract latent patterns. The result is numerical vectors that summarise the tastes of each user and the characteristics of each song.

Thus, each user has a "vector of musical taste" (X) and each song a "vector of characteristics" (Y) in a mathematical space of latent dimensions. If a user's vector is compared to that of a song, the degree of similarity indicates how much that user might like that song. With these user and song vectors calculated, collaborative filtering looks for matches: it identifies users with vectors close to ours (i.e. similar tastes) and songs whose vectors are close to those of our favourite songs.

Thus, when recommending a new song, it boils down to finding a track that is in the library of those similar users. In other words, it relies on the wisdom of the crowd. While collaborative filtering has proven to be very effective, it has some limitations. It tends to favour the popular (it is easier to recommend songs that many people have already heard) and has problems with "newness": a newly released song or artist, with no play history, cannot be recommended by this method. To complement these shortcomings, Spotify resorts to strategies based on the content of the music itself.

Content-based filtering: tags and sound features

The content-based filtering approach consists of recommending songs with similar attributes to those liked by a particular user. Instead of comparing the libraries of other users, it examines the intrinsic characteristics of each track, based on a mathematical description: the textual context (what is said or written about the music) and the audio properties (what the recording sounds like).

To do this, it starts with a text and metadata analysis: although a song does not have descriptive text by itself, there is a multitude of text generated around the music: reviews, blogs, news, comments on social networks, etc. From here, using Natural Language Processing (NLP) techniques, the system collects the words and tags associated with artists and tracks from the Internet.

All this information is structured in matrices and vectors of terms, giving each song its own semantic profile. So if the user's history indicates that he or she enjoys songs described as "acoustic indie folk", the content algorithm can recommend other pieces with similar tags, even if they come from different artists.

Beyond textual tags, Spotify also directly analyses the "audio attributes" of songs using artificial intelligence. In this sense, it is important to note that each music track can be broken down into quantitative properties: tempo (BPM), key and mode, intensity or volume, energy level, 'danceability', positivity (valence), instrumentality, etc.

The algorithm extracts these objective sound features from the audio signal using specialised deep learning models. To do this, Spotify employs convolutional neural networks (CNNs) that process the audio spectrum in a similar way to how a neural network "sees" an image. This network learns to identify acoustic patterns, allowing it to compare songs by how they sound. For example, if a new song has a tempo, rhythmic structure and timbre very similar to another song we love, the system will be able to detect it.

So, by breaking down the music into numbers, filtering by sound content can find songs that "sound similar" to the user's preferences, even if they are from unfamiliar artists or genres. This is vital for discovering new music that has not yet been played. In short, Spotify's recommendation systems are hybrids: they combine collaborative filtering signals with content (text and audio) to match users' tastes.

It's not magic, it's mathematics.

More information

Degree in Mathematics Applied to Software Engineering

5 reasons why you should study mathematics applied to software engineering.

The perfect tandem for your future: mathematics and software engineering.

Related Insights

Un joven sonriente se encuentra de pie en una sala de reuniones con paneles de vidrio.
Ciencia y Tecnología

UDIT alumnus develops AI tool to boost business cooperation

6 October 2025

One of the great challenges in today's technological ecosystems is to identify opportunities for collaboration between agents with different profiles. This need was the starting point for the Master's thesis of Yannick José Medina, a student of the Master's in Artificial Intelligence at UDIT, who developed an innovative solution for Secpho, a cluster of companies specialising in DeepTech. His proposal: a conversational recommendation system based on artificial intelligence that facilitates and speeds up the connection between partners.

Una mujer sonriente con una blusa blanca y una falda negra con motivos, posa en un ambiente moderno de oficina.
Ciencia y Tecnología

Bills under control: UDIT alumni applying AI to save time and cut costs

29 September 2025

Belén Gómez is an alumniof the Master in Intelligence at UDIT. A firm advocate ofthe strong potential that this technology has to add value in different business areas, her TFM ("Extraction of invoice information with artificial intelligence") , carried out in collaboration with Tendamproposes a proof of concept to automate the extraction of invoice information using advanced AI tools.

Una jirafa camina por un paisaje natural.
Ciencia y Tecnología

More than ChatGPT: four projects unleashing the full power of Artificial Intelligence

8 September 2025

This article presents four projects that show how AI is already changing the way we live, care for ourselves and protect the planet. We talk about Google's revolutionary meteorological model capable of anticipating hurricanes with greater precision than official systems; GIRAFFE, a computer vision tool developed by Microsoft to save giraffes from extinction; the medical software implemented at the Clínica Universidad de Navarra, which improves the diagnosis of breast cancer; and a predictive system by Renfe that allows it to prevent graffiti on its trains in advance and efficiently.