Madrid is host to a variety of annual events each year. From religous festivities (a majority of Spain is Roman Catholic) to other celebrations, visiting Spain during these special events presents another unique travel opportunity. However, the crowds can get very large and hotels and restaurants can get full quickly, so be prepared for that.
So since Spain is largely Christian, espeically Catholic, Lent and Easter celebrations and events are very popular and important to the Spanish culture. The Carnival takes place before Lent starts as a type of Mardis Gras celebration.
New Years - In the Puerta del sol, the fireworks are plentiful and many Madrenos come out to celebrate. The custom is to eat a grape at every stroke of the clock. Big party potential here.
During "Easter week" (Semana Santa) there are often processions around Good Friday and Holy Thursday. There is a popular passion play Southeast of Madrid and the Plaza de la Comendadors has a large ceramics market sale.
May 1st - Spain loves it's holidays, especially ones that deal without working. So in the Puerta del Sol (the tourist/traveler hub where you'll be more than likely) there is a large gathering/rally/celebration that could be fun to witness.
May 2nd - Another similiar celebration for the Spanish military also takes place in the Puerta del sol in Madrid's center.
May 15th - The Patron Saint of Madrid is celebrated (San Isidoro). The Las Ventas has some of the year's best bullfighting action, and bands and music line the streets during the day.
Early June - Festimad- the city's rock festival takes place. Lots of music and people attend this popular musical festival.
October, November - Autumn festival - This autumn festival is a cultural mecca for Madrid as many vendors and people of all cultures come together and celebrate. The weather is beautiful and this is one of the premier events that takes place in Madrid.