The full title of the play is Twelfth Night, or What You Will. Subtitles for plays were fashionable in the Elizabethan era, and though some editors place The Merchant of Venice's alternative title, The Jew of Venice, as a subtitle, this is the only Shakespearean play to bear one when first published.
The play was probably finished between 1600 and 1601, a period suggested by the play's referencing of events which happened during that time. A law student, John Manningham, who was studying in the Middle Temple in London, described the performance on 2 February 1602 (Candlemas) which took place in the hall of the Middle Temple at the formal end of Christmastide in the year's calendar, and to which students were invited. This was the first recorded performance of the play. The play was not published until its inclusion in the First Folio in 1623.
"Twelfth Night" is a reference to the twelfth night after Christmas Day, called the Eve of the Feast of Epiphany. It was originally a Catholic holiday but, prior to Shakespeare's play, had become a day of revelry. Servants often dressed up as their masters, men as women and so forth. This history of festive ritual and Carnivalesque reversal, based on the ancient Roman festival of Saturnalia at the same time of year (characterized by drunken revelry and inversion of the social order; masters became slaves for a day, and vice versa), is the cultural origin of the play's gender confusion-driven plot. The source story, "Of Apolonius and Silla", appeared in Barnabe Riche's collection, Riche his Farewell to Militarie Profession conteining verie pleasaunt discourses fit for a peaceable tyme (1581), which in turn is derived from a story by Matteo Bandello.