Hamlet-like legends are so widely found (for example in Italy, Spain, Scandinavia, Byzantium, and Arabia) that the core "hero-as-fool" theme is possibly Indo-European in origin. Several ancient written precursors to Hamlet can be identified. The first is the anonymous Scandinavian Saga of Hrolf Kraki. In this, the murdered king has two sons—Hroar and Helgi—who spend most of the story in disguise, under false names, rather than feigning madness, in a sequence of events that differs from Shakespeare's. The second is the Roman legend of Brutus, recorded in two separate Latin works. Its hero, Lucius ("shining, light"), changes his name and persona to Brutus ("dull, stupid"), playing the role of a fool to avoid the fate of his father and brothers, and eventually slaying his family's killer, King Tarquinius. A 17th-century Nordic scholar, Torfaeus, compared the Icelandic hero Amlodi and the Spanish hero Prince Ambales (from the Ambales Saga) to Shakespeare's Hamlet. Similarities include the prince's feigned madness, his accidental killing of the king's counsellor in his mother's bedroom, and the eventual slaying of his uncle.
Many of the earlier legendary elements are interwoven in the 13th-century Vita Amlethi ("The Life of Amleth") by Saxo Grammaticus, part of Gesta Danorum. Written in Latin, it reflects classical Roman concepts of virtue and heroism, and was widely available in Shakespeare's day. Significant parallels include the prince feigning madness, his mother's hasty marriage to the usurper, the prince killing a hidden spy, and the prince substituting the execution of two retainers for his own. A reasonably faithful version of Saxo's story was translated into French in 1570 by François de Belleforest, in his Histoires tragiques. Belleforest embellished Saxo's text substantially, almost doubling its length, and introduced the hero's melancholy.
According to a popular theory, Shakespeare's main source is believed to be an earlier play—now lost—known today as the Ur-Hamlet. Possibly written by Thomas Kyd or even William Shakespeare himself, the Ur-Hamlet would have been in performance by 1589 and the first version of the story known to incorporate a ghost. Shakespeare's company, the Chamberlain's Men, may have purchased that play and performed a version for some time, which Shakespeare reworked. Since no copy of the Ur-Hamlet has survived, however, it is impossible to compare its language and style with the known works of any of its putative authors. Consequently, there is no direct evidence that Kyd wrote it, nor any evidence that the play was not an early version of Hamlet by Shakespeare himself. This latter idea—placing Hamlet far earlier than the generally accepted date, with a much longer period of development—has attracted some support, though others dismiss it as speculation.
The upshot is that scholars cannot assert with any confidence how much material Shakespeare took from the Ur-Hamlet (if it even existed), how much from Belleforest or Saxo, and how much from other contemporary sources (such as Kyd's The Spanish Tragedy). No clear evidence exists that Shakespeare made any direct references to Saxo's version. However, elements of Belleforest's version which are not in Saxo's story do appear in Shakespeare's play. Whether Shakespeare took these from Belleforest directly or through the Ur-Hamlet remains unclear.
Most scholars reject the idea that Hamlet is in any way connected with Shakespeare's only son, Hamnet Shakespeare, who died in 1596 at age eleven. Conventional wisdom holds that Hamlet is too obviously connected to legend, and the name Hamnet was quite popular at the time. However, Stephen Greenblatt has argued that the coincidence of the names and Shakespeare's grief for the loss of his son may lie at the heart of the tragedy. He notes that the name of Hamnet Sadler, the Stratford neighbour after whom Hamnet was named, was often written as Hamlet Sadler and that, in the loose orthography of the time, the names were virtually interchangeable. Sadler's first name is spelled "Hamlett" in Shakespeare's will.
Scholars have often speculated that Hamlet 's Polonius might have been inspired by William Cecil (Lord Burghley)—Lord High Treasurer and chief counsellor to Queen Elizabeth I. E. K. Chambers suggested Polonius's advice to Laertes may have echoed Burghley's to his son Robert Cecil. John Dover Wilson thought it almost certain that the figure of Polonius caricatured Burleigh, while A. L. Rowse speculated that Polonius's tedious verbosity might have resembled Burghley's. Lilian Winstanley thought the name Corambis (in the First Quarto) did suggest Cecil and Burghley. Harold Jenkins criticised the idea of any direct personal satire as "unlikely" and "uncharacteristic of Shakespeare", while G.R.Hibbard hypothesised that differences in names (Corambis/Polonius:Montano/Raynoldo) between the First Quarto and other editions might reflect a desire not to offend scholars at Oxford University.