Is 9:50 the time of departure or last boarding? If there's no delay on the first flight, you should be able to make it, however it's a bit risky.
Madrid Barajas is a huge airport, with 4 terminals. Spanair flights operate on terminal 2, and Iberia operates on T4, so unfortunately you'll need to take bus to change terminals. It should not take you more than 20 minutes. The airport is quite easy to navigate, terminals and routes are well signed, but be prepared you'll need to hurry, as the distances are quite long.
Have you considered staying in Madrid overnight and taking Iberia to LHR on the next day? You can reach the city by underground from Terminal 2, in just 20-30minutes. (2 euros)