Heather & Mark,
Due to unforeseen delays (flight, passport control, etc...) it’s best to wait to buy your day of arrival train tickets at the airport.
This is exactly what we did the last time we traveled to Córdoba on our day of arrival. We bought our tickets at the Renfe ticket office (Terminal 4).
Your AVE ticket will include a “Combinado Cercanías” (a combined ticket) that will allow you to take the commuter train from the airport to Madrid for free. You can get these tickets from the Cercanías ticket machine(s) right across the ticket office.
You’ll then take the C1 or C10 Cercanías train to Puerta de Atocha train station.
You’ll arrive to Puerta de Atocha on the lower level. The AVE train platforms are on the upper levels.
Puerta de Atocha is a huge train station and I found it a bit confusing especially since I was suffering from sleep deprivation and jet lag. There are Renfe employees in uniform (purple vest) whom you can ask for assistance if necessary.
Wishing you a wonderful trip!
Edited to add...
Here’s a Map of Puerta de Atocha Station.
The Cercanías train will arrive on the lower level (The Cercanías icon is a red circle with a white “C” facing backwards)
Hope this helps!