Macbeth cannot be dated precisely, owing to significant evidence of later revisions. Some scholars have placed the original writing of the play as early as 1599. As the play may celebrate King James' ancestors and the Stuart accession to the throne in 1603 (James believed himself to be descended from Banquo), some scholars believe that the play is unlikely to have been composed earlier than 1603 and suggest that the parade of eight kings—which the witches show Macbeth in a vision in Act IV—is a compliment to King James. Some critics think the play was written in 1606 in the aftermath of the Gunpowder Plot because of possible internal allusions to the 1605 plot and its ensuing trials. In fact, there are a great deal of allusions and possible evidences alluding to the Plot, and, for this reason, a great number of critics agree that "Macbeth" was written in the year 1606. Lady Macbeth's instructions to her husband, "Look like the innocent flower, but be the serpent under't" (1.5.74–5), may be an allusion to a medal that was struck in 1605 to commemorate King James' escape that depicted a serpent hiding among lilies and roses .
Particularly, the Porter's speech (2.3.1–21) in which he welcomes an "equivocator", a farmer, and a tailor to hell (2.3.8–13), has been argued to be an allusion to the 28 March 1606 trial and execution on 3 May 1606 of the Jesuit Henry Garnet, who used the alias "Farmer", with "equivocator" referring to Garnet's defence of "equivocation". The porter says that the equivocator "committed treason enough for God's sake" (2.3.9–10), which specifically connects equivocation and treason and ties it to the Jesuit belief that equivocation was only lawful when used "for God's sake", strengthening the allusion to Garnet. The porter goes on to say that the equivocator "yet could not equivocate to heaven" (2.3.10–11), echoing grim jokes that were current on the eve of Garnet's execution: i.e. that Garnet would be "hanged without equivocation" and at his execution he was asked "not to equivocate with his last breath." The "English tailor" the porter admits to hell (2.3.13), has been seen as an allusion to Hugh Griffin, a tailor who was questioned by the Archbishop of Canterbury on 27 November and 3 December 1607 for the part he played in Garnet's "miraculous straw", an infamous head of straw that was stained with Garnet's blood that had congealed into a form resembling Garnet's portrait, which was hailed by Catholics as a miracle. The tailor Griffin became notorious and the subject of verses published with his portrait on the title page.
When James became king of England, a feeling of uncertainty settled over the nation. James was a Scottish king, not to mention the son of Mary Queen of Scots, a staunch Catholic and traitor. In the words of critic Jonathan Gil Harris, “Macbeth was a play for a post-Elizabethan England facing up to what it might mean to have a Scottish king. England seems comparatively benign, while its northern neighbour is mired in a bloody, monarch-killing past...Macbeth may have been set in medieval Scotland, but it was filled with material of interest to England and England's ruler.”  Critics argue that the content of the play is clearly message to James, the new Scottish Catholic King of England. Garry Wills provides further evidence that "Macbeth" is a Gunpowder Play (a type of play that emerged immediately following the events of the Gunpowder Plot). He points out that every Gunpowder Play contains "a necromancy scene, regicide attempted or completed, references to equivocation, scenes that test loyalty by use of deceptive language, and a character who sees through plots—along with a vocabulary similar to the Plot in its immediate aftermath (words like train, blow, vault) and an ironic recoil of the Plot upon the Plotters (who fall into the pit they dug)." 
The play utilizes a few key words that the audience at the time would recognize as allusions to the Plot. In one sermon in 1605, Lancelot Andrewes stated, regarding the failure of the Plotters on God's day, "Be they fair or foul, glad or sad (as the poet calleth Him) the great Diespiter, 'the Father of days' hath made them both." Shakespeare begins the play by using the words "fair" and "foul" in the first speeches of the witches and Macbeth. In the words of Jonathan Gil Harris, the play expresses the "horror unleashed by a supposedly loyal subject who seeks to kill a king and the treasonous role of equivocation. The play even echoes certain keywords from the scandal-the 'vault' beneath the House of Parliament in which Guy Fawkes stored thirty kegs of gunpowder and the 'blow' about which one of the conspirators had secretly warned a relative who planned to attend the House of Parliament on 5 November...Even though the Plot is never alluded to directly, its presence is everywhere in the play, like a pervasive odor."  Further, the play could not have been written after this time, due to references to it seen in other works, notably Francis Beaumont's Knight of the Burning Pestle, which was written in 1607-1608. Lines 21-30 are a clear allusion to the scene in which Banquo's ghost visits and haunts Macbeth at the dinner table:
In any place, but I will visit thee With ghastly looks, and put into thy mind The great offences which thou didst to me: When thou art at thy table with thy friends, Merry in heart, and filled with swelling wine, I'll come in midst of all thy pride and mirth, Invisible to all men but thyself, And whisper such a sad tale in thine ear Shall make thee let the cup fall from thy hand, And stand as mute and pale as death itself.
Scholars also cite an entertainment seen by King James at Oxford in the summer of 1605 that featured three "sibyls" like the weird sisters; Kermode surmises that Shakespeare could have heard about this and alluded to it with the weird sisters. However, A. R. Braunmuller in the New Cambridge edition finds the 1605–6 arguments inconclusive, and argues only for an earliest date of 1603. The play is not considered to have been written any later than 1607, since, as Kermode notes, there are "fairly clear allusions to the play in 1607."
In addition, one suggested allusion supporting a date in late 1606 is the first witch's dialogue about a sailor's wife: "'Aroint thee, witch!' the rump-fed ronyon cries./Her husband's to Aleppo gone, master o' the Tiger" (1.6–7). This has been thought to allude to the Tiger, a ship that returned to England 27 June 1606 after a disastrous voyage in which many of the crew were killed by pirates. A few lines later the witch speaks of the sailor, "He shall live a man forbid:/Weary se'nnights nine times nine" (1.21–2). The real ship was at sea 567 days, the product of 7x9x9, which has been taken as a confirmation of the allusion, which if correct, confirms that the witch scenes were either written or amended earlier than July 1606.
Macbeth was first printed in the First Folio of 1623 and the Folio is the only source for the text. The text that survives had been plainly altered by later hands. Most notable is the inclusion of two songs from Thomas Middleton's play The Witch (1615); Middleton is conjectured to have inserted an extra scene involving the witches and Hecate, for these scenes had proven highly popular with audiences. These revisions, which since the Clarendon edition of 1869 have been assumed to include all of Act III, scene v, and a portion of Act IV, scene I, are often indicated in modern texts. On this basis, many scholars reject all three of the interludes with the goddess Hecate as inauthentic. Even with the Hecate material, the play is conspicuously short, and so the Folio text may derive from a prompt book that had been substantially cut for performance, or an adapter cut the text himself.