Of course, you should visit both. And with the high-speed AVE train now serving the route between Madrid and Barcelona, the journey is quicker and easier than ever.
But if you do have to choose, here's a breakdown of the pros and cons of each city.
Value for Money
Barcelona is a much more touristy city than Madrid. And tourists bring prices up. It's not that Barcelona doesn't have cheap things to do, it's just that there are much more of them in Madrid.
In Madrid, you can get cod tapas thirty seconds from Sol (Madrid's main square) at Casa Labra for a euro or a great meal for 10 euros just off Gran Via (Madrid's main street) at Con Dos Fogones. The equivalent restaurants in Barcelona are too busy doing paella and sangria 'deals' to offer real value for money.
Meanwhile, Madrid's two best museums (the Reina Sofia and the Prado) have a free entry every night of the week, something you'd never see in Barcelona.
Access to the Rest of Spain
Heard of Toledo and Segovia? They're both near Madrid. The satellite cities around Madrid are some of Spain's most interesting and diverse. Barcelona also has some good day trips, including Figueres (for the Dali museum) and Sitges (for the beach), but Madrid's day trips are unbeatable.
When it comes to exploring the rest of Spain, Madrid's central location makes it far superior to the north-eastern Barcelona. The AVE train can get you to many Spanish cities incredibly quickly, while normal trains and buses will get you everywhere else.
Architecture is the main reason tourists visit Barcelona. Most of Gaudi's madcap modernist buildings are in Barcelona and it is in these designs that the city's reputation is hinged. Madrid has some attractive buildings, especially along Gran Via, but it can't compete with Barcelona.
Catalan cuisine is well respected throughout Spain. Not far from the touristy areas of Barcelona you'll find some great food, but it takes more effort than in Madrid, and you'll always end up paying more. A good tour company, such as Food Lovers Company, can ensure you're not disappointed.
Eating out in Madrid is less difficult. The restaurant scene in the capital takes in all the regions of Spain and countries of the world and it isn't spoiled by the kind of tourist-focussed eateries that plague Barcelona.
Though both cities have an abundance of language schools, language exchange evenings, and people looking to meet and practice their language skills, the important thing to remember is that the main language in Barcelona is Catalan, not (Castilian) Spanish.
For this reason, alone, Madrid wins.
Madrid has three of Spain's most famous art museums: the Prado (which ranks up there with the Louvre for pre-20th century art), the modern art of the Reina Sofia (featuring Picasso's masterpiece, the Guernica), and the Thyssen-Bornemisza, said to be one of the best private art collections in the world.
Barcelona has a beach, Madrid doesn't. Or at least not a real one. But in 2011, Madrid council unveiled Madrid Rio, a new complex by the Manzanares river publicized as having its own beach, but it doesn't really—just a place to sunbathe (the Retiro Park as just as good for this). But if you want a real beach, you need a coast. There are plenty of beaches in Barcelonas, as well as just outside its borders, making this city a good destination for catching some rays.
It would be difficult to argue anything other than Barcelona for this one. Barcelona's proximity to the Mediterranean gives it slightly cooler summers than Madrid, but milder winters and springs. Madrid has great springs and falls, but winter and summer can be a little on the extreme side.
Both cities have packed event calendars.
Barcelona has both the Primavera Sound and Sonar music festivals, as well as the neighborhood celebrations of Gracia and Merce. Meanwhile, Madrid's gay district, Chueca, gives Spain one of its most flamboyant carnival seasons (not to mention Gay Pride).
Kids are well looked after in both Madrid and Barcelona. There are some good science museums in both cities. Kids will appreciate the modern art of Picasso and Dali (perhaps more than most adults), and there's plenty of them in both cities. But it is Barcelona's modernist art that, like with their parents, will capture the children's imagination the most.
Two of the best nightclubs are in Barcelona (Sidecar and Razzmatazz). However, while Barcelona has some great individual bars and clubs, Madrid has whole streets of cool nightspots. Whatever your age or taste in music, Madrid will have somewhere for you.
Madrid's appeal is a little more subtle; it takes much longer to get a real feel for the capital than for Barcelona. You could find several reasons for this - the architecture of Barcelona is an obvious point in its favor, as is its setting between the mountains of Montjuic and Tibidabo and its more obvious 'center'. If you only had a weekend in Spain, you'd feel like you 'got' Barcelona much faster than you would Madrid.
On the other hand, the longer you stay in Madrid, the more you'll appreciate it.
Final Score: Tie
Gaudi has a lot to answer for. Through his weird and wacky architecture, Barcelona has become the city that captures the imagination of most visitors to Spain. If you have only a brief time in the city, you cannot fail to be impressed by Barcelona.
But take a little more time and Madrid's charms become apparent. Cheaper, with more variety, better food, and generally more to do than Barcelona, Madrid gets the top prize for a longer trip.
If you're in the south of France and want a quick weekend in Spain and to experience Gaudi's architecture, Barcelona is the one for you. But if you have a week to spare to explore a bit more and you like art, go to Madrid.