August will be hot in Spain, so consideration needs to be given to how much history your family wants and how much pool or beach time.
I love the history and the museums. But your fam may have different choices.
We’ve been to Spain twice, probably 5 weeks total and we have friends who live there. Barcelona is just fantastic with architecture and art (the Picasso and Miro museums) and it has beaches in town. So that’s worth at least three, perhaps four nights.
Highways in Spain are excellent, so that may be liberating for your family of 5, in terms of travel. You should compare car rental costs vs train fares for five.
Both Segovia and Toledo are reasonable day trips from Madrid. Four nights in Madrid could allow you to have one day in each plus one day - and 3 nights - in Madrid. Or a day in Segovia, two days in Madrid, and a few hours in Toledo as a stop on the way to Cordoba. Check drive times. Barcelona to Madrid is probably 4-1/2 hours. Madrid to Cordoba via Toledo is about the same. Madrid has three fantastic museums, if art and museums appeal. The Prado (one of the world’s greats), the Thyssen (wonderful for impressionists and 20th century art) and the Reina Sofia - modern art, but perhaps most importantly, studies for - and the final masterpiece of - Picasso’s Guernica.
Cordoba and Granada would be a great pair of cities to visit in the south. Remarkable cities and great sights including the Mezquita in Cordoba and the Alhambra in Granada, as well as places that were central to the triumphs and glories of two of the most famous monarchs of all time - or tyrants depending on your point of view - King Ferdinand and Queen Isabella. Historic and interesting as Seville is, I just don’t think you have the time to include it. With Cordoba and Granada as parts of your trip, I am not sure that Seville adds that much given your 12 day limit.
Or, if beaches are a higher priority, you could head back to Barcelona from Madrid and wander up to Figueres (Dali was from there) and the coast near there.
I’ve never been to Figueres and thereabouts, nor Valencia, so I have nothing to offer there. Should we get back to Barcelona to see the Sagrada Familia once it is finished, Figueres and costal sites near there are of interest to me.
Have a great trip, whatever you do.