Travelling by train in Spain is a good option.
The trains and railways are with high quality and the prices are very affordable.
If you choose to go with high speed trains Renfe AVE (Alta Velocidad Española) you will arrive quickly with speeds over 300 km/h.
These high speed trains are operating in almost all of Spain. For example Madrid-Barcelona in 2.5 hours or Málaga-Madrid 5 minutes more.
If you are traveling a shorter distance you can select AVANT or the little slower and cheaper MD