You can find timetables and tariffs and book on line at renfe.es - good luck, it's an absolute minefield! I think you have to register before you can make a booking. You can buy tickets over the phone or at stations too, but it costs more. You could use a travel agent, but they will charge a fee (well earned I reckon, having tried to fathom out the website).
Last time I looked, it was about €100 return trip. (Coupled with the extortionate price for renewing a British passport at an overseas embassy, I decided it was cheaper to fly to England and do it here and see family at the same time. Shame, 'cos I really fancied taking the train and seeing a bit of Madrid).