You do not say how many days you have. I would spend at least 4 days in Madrid and do one day trip to Toledo and another to Segovia. Read the top questions in the Madrid forum about these day trips. There are other day trips that you can do from Madrid, depending on the time you have.
Zaragoza is midway between Madrid and Barcelona and you can take the AVE to that city and to Barcelona afterwards. Read Buying Renfe Tickets Online. Read the top questions in the forums of each city to find out the sights.
As Benny said above, all may depend on how many days you have.
There are several possibilities for daytrips from both Madrid and Barcelona, and different possibilities for travelling from Madrid to Barcelona: you can go direct by AVE train in less than 3 hours.... or you can stop in Zaragoza for a day or two... or you may spend a whole week or two (or even more, without running out of things to see and do) driving and stopping in nice towns and villages, via Zaragoza... or via Valencia... or via some "unknown gems" as Cuenca and Teruel... etc.
-:- Message from TripAdvisor staff -:-
This topic has been closed to new posts due to inactivity. We hope you'll join the conversation by posting to an open topic or starting a new one.
To review the TripAdvisor Forums Posting Guidelines, please follow this link: http://www.tripadvisor.com/pages/forums_posting_guidelines.html
We remove posts that do not follow our posting guidelines, and we reserve the right to remove any post for any reason.