It was written for Haydn's patron, Prince Nikolaus Esterházy, while he, Haydn and the court orchestra were at the Prince's summer palace in Eszterháza.
The stay there had been longer than expected, and most of the musicians had been forced to leave their wives back at home in Eisenstadt, so in the last movement of the symphony, Haydn subtly hinted to his patron that perhaps he might like to allow the musicians to return home: during the final adagio each musician stops playing, snuffs out the candle on his music stand, and leaves in turn, so that at the end, there are just two muted violins left (played by Haydn himself and the concertmaster, Alois Luigi Tomasini).
Esterházy seems to have understood the message: the court returned to Eisenstadt the day following the performance