May to September is best, with White Nights the peak. Winter is cold and dark, but beautiful. Go in early May, September and October to avoid the crowds.
During the major holiday periods – the first week in January (between New Year’s Day and Orthodox Christmas) and the first week or two of May (around May Day and Victory Day) – St Petersburg empties out as many residents retreat from the city. Transport can be difficult to book around these periods, but accommodation is usually not a problem. Although many residents leave, the city is a festive place over New Year’s and during the May holidays, usually hosting parades, concerts and other events. The downside is that many museums and other institutions have shortened hours or are closed altogether on some days during these periods.
By contrast, the Stars of White Nights Festival was designed with tourists in mind: theatres, museums and other institutions often host special events between late May and early July to appeal to the massive influx of visitors during this period. If you are visiting St Petersburg at this time, book your travel and accommodation in advance and expect to pay top rates.