From this Website http://www.gomadrid.com/transport/madrid-transport.html, you will read the information below
Quote
Madrid's Barajas Airport is situated approximately 15 KM (7m) from the city centre and has four terminals. You are strongly recommended to consult your airline to find out which terminal your flight arrives at or leaves from, but we give here some basic indications:-
T1 International Terminal: Inter-continental and some European flights.
T2 Terminal: Mostly European flights. Some intercontinental flights
T3 Puente Aereo Terminal: Shuttle flights between Madrid and Barcelona
T4 Terminal: Iberia and other OneWorld alliance airline flights
Madrid's Barajas Airport has Metro stations in Terminal T2 and the newer Terminal T4. Trains leave every 5 minutes from 6.00am to 2.00am. Line 8 goes straight to the newly reformed Nuevos Ministerios Metro station in the centre of Madrid, with a journey time of just 12 minutes. On your return it is even possible to check-in at this Metro station for some flights between the hours of 6.30am and 10.30pm. Please check with the airline first, because not all flights are available (e.g. there is no check-in for the Madrid-Barcelona shuttle flight, and many foreign airlines have no presence here yet). You can check in your luggage up to 24 hours (20 hours for some companies) maximum and 2 hours minimum before the flight but again, please check with the relevant airline because certain goods have to be checked in at the airport itself (live animals, dangerous goods, etc.).
The price of a single journey to or from the airport is currently 2 euros, which includes a 1 euro supplementary airport charge. If you already possess a valid Metro ticket, you can simply purchase the airport supplementary ticket for 1 euro.
Tip: Consider buying the Madrid Tourist Travel Pass, which allows you to travel on any Metro, bus or suburban train, all included in the price of just 5 euros, making it a great way to save money on public transport. With this pass, it is not necessary to pay the airport surcharge.
It is also possible to purchase a 10-trip "Metrobus" ticket at 7.40 euros, valid for both the Metro and city buses, since you will undoubtedly be using the Metro again during your stay. This may be purchased at newspaper outlets, "estancos" or tobacconists and Metro stations. Note that you will still need to purchase the 1 euro supplementary ticket for any journey to/from the airport.
Advantages: Cheap, frequent service to virtually any part of town.
Disadvantages: You will most likely need to transfer a couple of times to get to your final destination. Consider this when lugging about large suitcases!
Cost: 2 euro one-way (to/from the airport, 1 euro elsewhere). 7 euros for 10 journeys (plus 1 euro supplement to/from airport)
Unquote
I remember that the trip to the city was convenient. Every year, fares change so expect that the quoted fares may not be the same anymore.

