The events of Twelfth Night take place in the coastal nation of Illyria, which shares its name with an ancient region in the western part of the Balkan Peninsula. During Classical Antiquity, Illyria encompassed the eastern coast of the Adriatic Sea and overlapped parts of modern-day Serbia, Slovenia, Bosnia, Albania, Croatia, and Montenegro. During Shakespeare's time, this region was controlled by the Republic of Venice, and the fictional Illyria of Twelfth Night seems largely inspired by 17th-century Italy.
When writing Twelfth Night, Shakespeare borrowed heavily from the Italian comedy G'ingannati or "The Deceived Ones," and several aspects of the play reflect an Italian setting. For example, Viola and Sebastian's fictional homeland of Messaline is likely a reference to Messina, Italy, and the currency used in Illyria is the Italian ducat. In addition, the majority of the play's characters have Italian names—e.g. Valentine, Malvolio, and Antonio.
Shakespeare set several other comedies in Italy, including The Merchant of Venice, Much Ado About Nothing, The Taming of the Shrew, and Two Gentlemen of Verona. Italy was a popular comedic setting during his time, since Elizabethan audiences associated the Mediterranean climate with hot-blooded behavior, festivity, and romance. These connotations were partly the result of racist medical doctrines that linked personality to ethnicity and partly due to that fact that romantic poetic forms like the sonnet, which were popular in England, all originated in Italy.
Despite all of its Italian characteristics, Illyria is also somewhat inspired by 17th century London. A few characters, most notably Sir Toby Belch and Sir Andrew Aguecheek, have quintessentially English names, and the play also contains references to contemporary English events and locations. The Elephant Inn in Illyria, for example, is likely a reference to the Elephant pub in London, which was located nearby the Globe Theatre.
Within Illyria, Twelfth Night largely takes place in two locations: Orsino's court and Olivia's house. Orsino's court, which is populated almost entirely by men, is a place of constant revelry and music. Olivia's house, by contrast, is in full mourning, and the staff is presided over by the cheerless Malvolio. Within this household, the individuals with the most power and agency—Olivia and Maria—are both women. Throughout Twelfth Night, Viola and Feste are the only characters able to freely travel between the two locations. Viola's androgyny means that she is able to enter both male and female spaces while never truly belonging in either, while Feste's job as a professional fool allows him to transcend barriers of class and gender.