The story of Hamlet is set in the late middle ages (14th and 15th centuries or, 1300 to 1499) in and around (mostly) the royal palace in Elsinore, a city in Denmark.
Despite the story's very specific location and time, the play has a distinct 16th century vibe. (Remember, Hamlet was written between 1599 and 1601). What do we mean by that? Well, for starters, there are several allusions to the Protestant Reformation, which wasn't initiated until around 1517 (that's when Martin Luther laid out his beef with the Catholic Church in his Ninety-five Theses). Denmark (like England) was a Protestant nation at the time Shakespeare wrote the play and Hamlet seems to be the quintessential Protestant kid – he goes to school in Wittenburg, Germany (where Martin Luther hung out) and he's also skeptical of the Ghost, who claims to be his father's Purgatorial spirit. (Protestants rejected the notion of Purgatory as mere "superstition" – you can read more about this in our discussion of "Religion.")
There's also a whole lot of play-acting in Hamlet, including a performance of The Murder of Gonzago, which is put on by a troop of traveling players (actors) who drop by the castle and decide, what the heck, why not put on a little show. That's just the kind of thing that would have gone down in Elizabethan England. (Be sure to check out "Art and Culture" for more on this.)
We should also point out that contemporary directors of stage and film versions of Hamlet have set the play in places and periods ranging from Elizabethan England to nineteenth century Europe to twenty-first century New York City. In the latter case, Gertrude and Claudius run a high-powered New York corporation and the ghost of Old Hamlet appears on security televisions in the company's offices. The fact that this setting somehow works is a testament to the universality and relevance of the play's themes, don't you think?
Whatever the physical setting, it's important to understand that the dynamic of the royal court of Denmark is high-powered and manipulative. Public image matters. Hamlet's emotional struggles and madness are not just playing out in his own home: his strange behavior is a liability to his parents, and they have a political interest in bringing him under control. "Madness in great ones must not unwatched go," says Claudius (3.1.188). So imagine if the president's children started acting as strangely as Hamlet does. The same dynamic is happening in Hamlet – the first son is totally off-the-wall, and Claudius and Gertrude are desperately attempting damage control. It's a big political nightmare for Claudius and Gertrude.
Of course, the royal court isn't the only place Hamlet hangs out. If you want to think about the setting of, say, the graveyard, check out "Symbols, Imagery, Allegory."