Madrid is a sunny place. Even in the winter, when the temperature drops, there usually are a few hours of sunshine.
In the summer it gets really hot with temperatures into the upper 30°C (90 Fahrenheit) or more! That’s why in August a lot of bars and restaurants close and most offices work from 8 am till 3 pm. Families that live in Madrid trade the city for the mountains or the coast. Meaning, the city isn’t crowded at all, which would make it a good time to visit if you can stand the heat!!!
In the winter it can become very cold. So, that leaves Spring and Autumn to be good times to visit the city. Because of comfortable temperatures, May/June and October are the best time to visit Madrid.