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

Una oficina moderna con un escritorio ordenado, un portátil y diversos libros y revistas sobre diseño arquitectónico.
Videojuegos, Branding, Interiores, Creación gráfica, Producto, Ciencia y Tecnología, Moda, Animación & UX

How to choose a Master’s degree: what to look for beyond the programme’s name

28 October 2026

Choosing a master’s degree requires comparing what a programme advertises with the information actually provided in its academic documentation. Comparing degree programmes is not simply a matter of looking at their names or syllabuses, but of checking five key aspects: the focus of the curriculum, the prior knowledge required, the skills and projects covered, the delivery method, and the academic nature of the qualification.

La imagen muestra un fondo abstracto que combina elementos de gráficos de datos y patrones dinámicos en tonos azules y dorados.
Ciencia y Tecnología

From data analysis to a decision: what to check before taking action

20 October 2026

A data-driven decision uses analysed information to compare alternatives or justify a course of action, but does not in itself eliminate uncertainty. Having well-organised records, dashboards or numerical estimates does not guarantee that a course of action will solve the anticipated problem, nor that its costs will be outweighed by the expected benefits. Before turning a result into a recommendation, it is worth asking the following question: what makes a data analysis sufficiently reliable and relevant to justify a decision?

Un grupo de estudiantes sentados en un aula prestando atención.
Videojuegos, Branding, Interiores, Creación gráfica, Producto, Ciencia y Tecnología, Moda, Animación & UX

How to tell if a creative or tech career is right for you: take a look at the work that goes into it

30 September 2026

To find out whether a degree course is right for you, it is not enough simply to ask yourself whether you like the outcomes. It’s worth finding out which tasks recur during your studies and in your work, what difficulties are part of the process, what problems arise in the curriculum, and what projects you’ll need to learn to tackle. Making a better choice means replacing an idealised image of the profession with evidence that’s closer to how the work is actually done.

Un grupo de jóvenes prestando atención en un aula moderna.
Ciencia y Tecnología

What goes on behind the scenes: software, data and artificial intelligence within a digital product

25 September 2026

A simple function within an app may depend on dozens of invisible components. The software receives an action and executes logic; the data reveals what is happening and what happened previously; and, when the problem requires predicting, classifying, recommending or generating a response, an artificial intelligence model may come into play. Understanding a digital product requires distinguishing between these layers and, above all, understanding how they depend on one another.

Un orador presenta frente a un público joven en una biblioteca.
Videojuegos, Branding, Interiores, Creación gráfica, Producto, Ciencia y Tecnología, Moda, Animación & UX

Learning by doing in design and technology: from the initial idea to a solution you can defend

4 September 2026

Learning by doing does not mean replacing theory with projects. In Design and Technology, it means turning an idea into something that can be observed and tested, gathering information about its shortcomings, revising decisions and explaining why changes have been made. Learning takes place within this cycle of action, evidence, feedback and iteration, not solely in the final outcome.

Una multitud de personas se reúne en un espacio amplio y luminoso, interactuando entre sí.
Videojuegos, Branding, Interiores, Creación gráfica, Producto, Ciencia y Tecnología, Moda, Animación & UX

What to study if you’re into design and technology: a guide to finding your field of study

31 August 2026

If you’re interested in both design and technology, you don’t need to choose between creativity and technique, but rather to identify the type of problem you want to tackle. Disciplines such as Fashion, Interior Design, Product Design and UX, Visual Communication, Animation, Video Games, and Data Science and AI apply varying degrees of both tools depending on whether they focus on the body, space, use, meaning, time or systems.

Un grupo de jóvenes interactúa frente a varias pantallas de computadora en un entorno colaborativo.
Ciencia y Tecnología

How to use AI to study without stopping yourself from thinking: five checks to carry out before accepting an answer

24 July 2026

Using artificial intelligence to study can help you understand, practise and revise, but first you must check whether it is permitted, make an initial effort yourself, decide what role it will play, verify its answers and retain ownership of the process. Citing the tool does not replace the need for permission, nor does it automatically make its content a reliable source.