Renfe's AVE service offers an (arguably) superior way between the two cities. No major security hassles (just a very brief bag x-ray when entering Atocha, for example); no need for long airport-to-city transfers (Atocha is very central, Sants not too far from the Ramblas area). Very comfortable train cabins (with power ports if you want to charge your electronics or watch DVDs on your laptop). Good catering, friendly on-board service.
You can search on the Renfe website for fare specials to obtain the best promotional prices (even on one-way trips). The fares can change according to departure time; often, departing an hour earlier or later can be significantly cheaper. Look for Web specials and for Estrella discount fares (the latter will show a little gold star icon next to the fare. Last October I took an AVE in Club class - I paid an Estrella of about €120, as opposed to the standard fare of over €200. Similar discounts are also available in Preferente and Turistica classes, depending on the specific journey.
I'm not sure about the non-AVE overnight trains, since I didn't use them, but I did find these Renfe pages:
http://www.renfe.com/EN/viajeros/lar...trenhotel.html
http://www.renfe.com/EN/viajeros/lar.../estrella.html
Lastly, there is a dedicated European Rail Travel forum where people far more knowledgeable than me

answer questions about Spanish rail travel. FlyerTalk member
Palal has comprehensive knowledge, and he/she is very helpful and kind in answering questions on this topic (Kudos to Palal ^)
http://www.flyertalk.com/forum/europ...il-travel-654/