You need to get a guide book and read about the sights in each city. Madrid and Barcelona are rather different; many tourists have fairly strong preferences for one or the other and might split their days 5/3. You are in the best position to judge whether you'll ultimately want more time in Madrid or Barcelona. Keep in mind that on the 17th you'll probably be sleep-deprived and jet-lagged, so it would be prudent not to expect to accomplish much that day other than wandering around. I'd only count Dec 18 - 25, inclusive, for planning purposes.
Also read about the major/most convenient potential day-trips to see if any of them sound appealing enough to pull you out of the big cities--keeping in mind that the weather (especially in the area around Madrid) might be rather cool in late December, and it will get dark early everywhere. Among the most popular side-trips are:
Madrid: Toledo, Segovia, Avila, El Escorial, Cuenca. Cuenca requires early purchase of AVE train ticket to make the trip affordable.
Barcelona: Figueres (Dali), Montserrat (at altitude--potential weather impact). There are beachy destinations but I don't know what they're like in December.