Both of you are wrong for different reasons. The truth is more nuanced.
First, Madrid is very different from the rest of the country. Salaries are higher, still half of what our neighbors of the north have. 15k/20k sounds like a rest-of-the-country average.
Even in Madrid 40k€ is far from average, that it's more likely 28k.
40 is the salary for a very senior o very specialized programmer/analyst.
But there's a caveat that makes you closer to reality for Madrid and it's if you add forced pension and health insurance that the employer pays. It's around 40% on top of the raw salary, so someone earning 30k is really costing 42k to the employer.
After income tax, those 30k become 24k :(
But be aware that the London salaries upper tail is wider, possibly brought up by the quant firms (which are a different kind of company than most are accustomed)
levels.fyi gives 112kE as the median and 200kE/90% for London vs around 60kE for the median and 90kE/90% (pretax for both)
Glassdoor lists the average for SWEs for Madrid at 35k€ vs London at £66k (76k€) which even accounting for cost of living is quite a big difference