The Madrid airport is located along metro line 8 (pink). This line is has connections with lines 6, 10, 9 and 4. The metro can take you to and from all 4 terminals (terminal 4S is connected to terminal 4 by a separate tram which is free to use). The journey from the centre can take from 40mins to 2hrs. To access line 8 you will need to pay an additional 3€ supplement fee which can be paid at the machines at the airport. See more details here.
If you expect to use it extensively, we recommend you to get a Travel tourist pass or ‘Tarjeta Multi’, covering metro, bus and train in the city (to buy in a metro station).