Assuming that you land in Madrid after an exhausting overnight flight, you'll have five really usable days to play with. The arrival day will probably find at least one of you seriously sleep-deprived and jetlagged. The usual suggestions for the first day would be either to walk around outdoors in the sun (Retiro Park and the botanical garden are near Atocha rail station) or hop on a train to get to your other destination if you plan two separate hotel stays, intending to return to Madrid for the last few days of your trip.
To me, five days is borderline enough for Barcelona by itself. I would definitely not split my time between Barcelona and Madrid. Madrid has 3 really obvious side-trips (Toledo, Segovia, Cuenca), and Cordoba would also be doable. So even if you don't have much interest in Madrid's three large art museums or the Palacio Real, there's enough to do while staying in the city to fill all of your time.
Cuenca and Cordoba are far enough away that you need to use the very fast AVE train to reach them. Fares on those trains vary, with the cheapest tickets usually selling out long before the travel date. Last-minute tickets to either of those cities can be painfully expensive, so much so that you might consider them too costly for just a day-trip. So the first thing to do is look at ticket availability and fares to those two places (if they interest you) and see whether cheap tickets are still available on one of the days you plan to be in Madrid. For this, you should use the Renfe website. Understand that the fares you see today to Cuenca and Cordoba could be higher tomorrow. If you have trouble buying tickets from Renfe, try paying with PayPal, or buy from trainline.eu or loco2.com. Do not buy from RailEurope (usually much higher prices). Round-trip tickets will probably be somewhat cheaper than two one-way tickets.
For me, Toledo is the clear #1 day-trip from Madrid (actually worth more than one day). I'd rank Cordoba above Cuenca; perhaps they would be tied if you are interested in modern art. Cuenca has a couple of quite nice modern-art museums to go along with its extremely picturesque medieval district.
If the prospect of making a slew of day-trips is unappealing, you could spend a night or two in one of the other cities I've mentioned. That's the most you would want to do if you are big art fans and expect to spend a lot of time in Madrid's museums. My first choice for a second overnight stop would be Toledo. My second choice (subject to availability of a reasonable train fare) would be Cordoba.