From Madrid you can easily get a train out to Cercedilla, Colmenar Viejo, Tres Cantos and there is loads of good mountain biking (with some big hills). I can send you some GPS tracks if you want. These places are about 30-45 minutes from the centre by train. A bit closer is El Pardo which is an enormous park to the North of Madrid with some decent riding but I don't know it too well). Very close to the city (10 or 15 minute ride) is Casa de Campo – a big park where the XC World Cup has been held in the past. If you just want a blast around for an hour or two then there is nowhere better (I love the place!).
I know there is good road riding to the North too but don't know where. I can get routes from friends if you want though.
La Pinilla is a ski resort in the winter and does downhill in the summer – I know you can hire DH bikes and kit there as they have a deal with Specialized. Not sure where you could hire a decent mountain bike – I'll look around.
Get in touch if you want more info.