We were in Spain two summers ago, and spent some time in Madrid before going on to the Costa Del Sol. Yes, it is HOT in Madrid in the summer! But on the plus side, the time schedule is such that people sleep in late, take a siesta during the day, and then stay up all night, enjoying the cooler hours.
What I would wear to survive the heat:
1) Clamdiggers or walk shorts, with a loose flowy top or a top you don't mind sweating in (knits). You won't want to layer camis underneath. Too hot.
2) Comfortable walking shoes (lots of cobblestones). Sandals seem to make sense for the heat, but not if they have little support or cushioning. I would recommend shoes that are made of natural materials as synthetics will make you sweat horribly and you'll wind up with blisters.
3) Dresses and skirts!! Much cooler than shorts. In cotton or linen - no synthetics.
4) If you have to be out during the daytime hours, don't forget good sunscreen. You may even want a hat to protect yourself from the sun.
5) Don't use a backpack because of pick-pockets.
6) Cotton underwear. More breathable than synthetic.
7) Bra - look for a bra that is breathable. Chantelle makes a breathable bra that is designed to keep you cool in hot weather, and I can vouch for it. It wicks sweat outward and away from your body. Only downside is that the sweat can stain the bra over time, even if you constantly wash it. But if you hate sweaty bras, this one is great.
8) At night you *might* need - at very most - a very light weight cardigan or scarf to throw over your shoulders, but it doesn't really cool down that much in the city, unless you are on the coast line.
There's some great shopping in Madrid..... the food is good... and the frequent festivals are a lot of fun. It's definetly a party scene if you are in to that (we had our teens with us so we got a bit of a taste but we weren't out until all hours). Don't plan to get any sleep until late because it can get loud with all the crowds partying it up into the night.
Mostly you just want to stay out of the worst of the sun, which should be easy, since most businesses are closed during those hours.