If you plan to go to the art museums (Prado, Reina Sophia, etc.), I would try to be near Atocha station. We stayed at the Oxygen which has pods for sleeping and lockers for luggage. It has a 24 hr desk and was clean and near restaurants, laundromat, and grocery stores.
Reserva de tus próximas vacaciones en nuestros cápsulas Oxygen Hostel Cápsulas - Madrid. No es necesario que vayas a Japón para vivir esta experiencia. Nosotros, los mejores precios y la mejor comodidad en el centro de Madrid.
www.oxygenhostelcapsules.com
There is an airport bus direct to the airport. I have taken it several times and it is a good option (see link below). The Cercanías trains 1 and 10 also go direct to the airport from Atocha. If there is more than one in your party, the taxis from the city to the airport are capped at 30 euros and can be a good value.
The airport express service links Barajas with the city centre in 40 minutes for five euros. It runs 24 hours a day and accepts card payment.