Discover how to get anywhere by searching plane, train, bus, car and ferry routes
www.rome2rio.com
If you are 60 or older, buy a Tarjeta Dorada (Gold ticket) first, at the station. It costs ca. 6 Euros, and will give you 25% (!) discount on train tickets in Spain for a whole year.
Then buy your ticket to SdC! The Gold ticket may also give you a discount in museums, and maybe more places/venues. Ask.
The Atosha station in Madrid centro is mostly for south/east/west lines from Madrid.
Edit: The train ride from Madrid Chamartin to SdC is very nice. I like to sip a glass of red in the restaurant wagon, with a chicken and/or tuna sandwich, watching the landscape passing by.