Madrid is definitely the place to be for NYE, especially the Puerta del Sol, which is the epicenter of festivities in Spain, a bit like Times Square in New York for the USA. The most famous New Year’s tradition in Spain is eating 12 grapes, one for each gong at midnight. I think you'll have a blast if you head over to Puerta del Sol in Madrid during NYE, with a bottle of Cava (sparkling wine) in one hand and a handful of grapes in the other!
On another note, while Christmas is very much celebrated in Spain, know that the main holiday is actually Three Kings Day on January 6th, so you will find Spain to be still in the festive mood, later than when you would expect. Many of our traditional Christmas markets go on even into early January. Also on the night of Jan 5th many cities (especially in Madrid) have a big parade of the Three Kings (Los Reyes Magos) which is the traditional holiday celebrated in Spain on the morning of the 6th.
P.S. During the holiday season, we have a tradition in Spain of eating Turrón – a nougat-like sweet. I would be on the look out to try some. For sure, you can find a great selection of different turrónes at El Corte Inglés.