There is a regular, almost hourly, bus service from Madrid - takes about 2.5 hours and costs 17.40 euro
http://www.auto-res.net
(There is also a public bus that is much slower and cheaper.)
Madrid airport is HUGE but easy to follow the signs down many escalators to the underground where you can get a metro to a bus station.
Madrid has three bus stations where most of the buses that travel around Spain arrive at or depart from: Méndez Álvaro station, Avenida América station and Conde de Casal station. You need to go to Conde de Casal Station at Fernández Shaw, 1. taking the tube to Conde de Casal.
The trains run less frequently - also take about 2.5 hours and cost 16.50 euro.