The best time to book a hotel in Madrid for the best deals and availability depends on various factors, including the season, demand, and special events in the city. However, as a general rule, it is recommended to book your hotel at least 2-3 months in advance to secure the best deals and availability. The peak tourist season in Madrid is during the summer months of June to August, as well as during major events and festivals such as New Year's Eve and Semana Santa (Holy Week). During these times, hotels tend to be in high demand, and prices can be quite steep. Therefore, if you plan to visit Madrid during these peak periods, it is advisable to book your hotel well in advance, preferably 4-6 months ahead of your travel dates. On the other hand, the shoulder season (spring and fall) can offer more reasonable rates and better availability, with fewer crowds and pleasant weather. Booking your hotel 1-2 months ahead of your trip during these periods can help you secure a good deal. Lastly, if you are flexible with your travel dates and can plan your trip last minute, you may be able to score some great deals by booking your hotel just a few days before your arrival. This is especially true during the low season (winter months) when hotels are looking to fill up their rooms.