Maybe I am missing something, but I don't understand why you prefer to travel between MAD and BCN by train rather than plane, having arrived in MAD by plane.
There are four companies that, alltogether, have more than 50 daily flights MAD-BCN, so it is materially impossible for you to wait for 5 hours at Barajas to go to BCN, unless you arrive at Barajas at 1am or so.
The four companies are:
Iberia ,
Spanair ,
Air Europa , and
Vueling . Apart of the scheduled flights you will find in the Websites above, there's the Iberia Air Shuttle that doesn't need (actually doesn't allow) previous reservation. You buy your Air Shuttle (Puente Aereo in Spanish) ticket, go to the check-in desk, and receive a boarding card for the next available flight of this service. Expensive but convenient.
Anyway, if you decide to travel by train, the Website of RENFE, the National Train System is the one you mentioned. All day trains to BCN depart from Atocha, and the two night ones from Chamartin. To see how to get to and from the stations in both BCN and MAD, please refer to the Websites pointed by ggladman in his post, but be aware that in Madrid case, the Chamartin metro station is under improvement works and, depending on the time of your trip, it could be closed. I don't know if the route planner of the Madrid Transport Consortium takes this into account.