Hi Jenny
The flight from Heathrow to Madrid is 2hrs 20 mins, then you have a 1hr 20 mins wait at the airport before you fly to San Jose. That part of the journey will take around 10hrs 10 mins.
It's quite a long journey but definitely worth it - Costa Rica is a beautiful country.
Kind regards,
Olly, your editor