Either if you want to travel round Spain or if you just intend to go on a few trips round Madrid, train is definitely the most comfortable means of transport, and the one that allows you to see the best scenery.
Madrid's main long distance railway stations are: Atocha and Chamartín. They run both long distance and commuter trains. There are three more stations for commuter trains: Príncipe Pío, Recoletos and Nuevos Ministerios. More info on stations below.
RENFE is the National Railway Company. They run all the railways in Madrid. In their website you can see timetables, prices, destinations...You can also buy your tickets online with their Tiknet service. it is also possible to book your tickets on the Renfe phone below (Contact Renfe). If you want to get them personally you'll have to go to the ticket offices in Chamartín, Atocha, Nuevos Ministerios or Príncipe Pío. In any of them you can get national and international tickets. Offices in Atocha and Chamartín are open everyday, including weekends from 6.30 to 21.00, and those in Príncipe Pío and Nuevos Ministerios from 8.00 to 20.00 Monday to Friday. See below for the location of stations.