Shakespeare used as his source Raphael Holinshed’s Chronicles of England, Scotland, and Ireland, published in 1577, only about 30 years before Macbeth was written. Holinshed was a chronicler, but by no means an absolute historian: his accounts were influenced by myth and tradition. While the parallels between the play and Holinshed’s account are apparent, many details, both significant and trivial, were altered for Shakespeare’s artistic license and perhaps the political pressures of his time. Some notable inconsistencies between the stories include (these are presented in terms of what the Chronicles describe):

However, some amazing details made the cut, including the family trees, jesting between Banquo and Macbeth, the influence of the “Weird Sisters” (as well as that term), all of their prophecies (All Hails, Banquo’s sons as kings, no man of woman born, til Birnam Wood remove to Dunsinane), Lady Macbeth’s encouragement of the murder (due to her “unquenchable desire to bear the name of queen”), and Macbeth’s slaying of Macduff’s family. Even some of Shakespeare’s lines bear resemblance to those spoken by the figures in the Chronicles (but of course crafted to his artistic and stylistic purposes).
There is also evidence that Shakespeare used the Gowrie Conspiracy against King James VI of Scotland (later installed as James I of England) to provide structure and details for the play. King James had a vested interest in witchcraft (wrote Daemonologie and encouraged witch trials and persecution) and was considered to be a descendant of Banquo, so Shakespeare already had material with which to praise and please James in royal performances of the play, the first of which is said to quickly follow the sixth anniversary of Gowrie Day (a commemoration of James’ deliverance).
The Gowrie line had posed a threat to James previously, to which James’ response was to execute the guilty party. Thus James already had reason to suspect another Gowrie, just as Duncan had a negative experience with the former Thane of Cawdor. However, both were indebted to their hosts: James, monetarily, and Duncan, by way of gratitude for military services. Both kings visit their hosts with little forewarning, causing messengers to be sent ahead to call for preparation, and as is speculated, conspiracy. Each host act suspiciously at dinner, even leaving. The dagger plays an integral part in both accounts, as do the porters and the knocking at the gates: in the Gowrie Conspiracy, James is threatened by dagger until his cries bring his attendants, who are then confounded by a porter and must pound at the gates to get in. Further, the Earl of Gowrie (James' conspirator) consorted with people practiced in witchcraft and was publicly prophesied to attain heights of which he was not worthy.
Today’s historians are attempting to elucidate the story of the real Macbeth. From their general and largely agreed-upon findings, it is believed that Macbeth was the son of Findlaech mac Ruadri, Mormaer of Moray (a mormaer was an under-king or provincial ruler), and grandson of Scotland's current king, Malcolm II. Macbeth spent much of his childhood in Moray, learning and most likely practicing the martial skills that were so necessary in that time of political turmoil. He also spent much time in Malcolm II's court, especially after his father was killed while Macbeth was still young.
Findlaech appears to have been murdered by two ambitious nephews who wanted his title. Later, one of these men, along with fifty of his followers, was burned to death. It is speculated that it was an act of revenge performed by Macbeth, enacted after he had grown old enough to pose a threat and claim what he believed to be his rightful position. He soon thereafter became the Mormaer of Moray (c. 1031), also taking his cousin’s widow, Gruoch, as his wife.
Gruoch brought with her a son from her previous marriage. Macbeth adopted the boy, Lulach, probably to show loyalty to his new wife and from the obligation to care for his victim's progeny. But he also made Lulach his heir, indicating that he and Gruoch had no children of their own, or at least any that survived past childhood. Their marriage also brought together two competing claims to the Scottish throne: the dispossessed descendants of Boite (represented by Gruoch), and Malcolm II's line (Macbeth).
Meanwhile, King Malcolm II sought to establish primogeniture (inheritance by direct descent) instead of the traditional method of alternating succession between various branches of a family's tree (i.e., a man's position would go his nephew instead of his own son). To do so, he supposedly killed off a close relative of Gruoch’s, giving her motive for revenge but clearing the way for Malcolm II's eldest grandson, Duncan, to ascend to the throne in 1034. He immediately bestowed upon his oldest son, Malcolm Canmore, the province of Cumbria, identifying the boy as his heir.
Duncan was considered inadequate as a ruler, suffering defeats to Danish invaders and leading unsuccessful military campaigns. This combined with his possibly "unfair" path to the throne, Macbeth's own strong claims to the kingship, the established cycle of violence now embraced by Macbeth, and the probable influences of ambition, resentment, and his wife (who would have been a princess had her father not been excluded from the kingship) created an irresistable opportunity when Duncan made his way in Moray in 1040 after a series of defeats. The location of Duncan's death suggests that he had advanced on Macbeth, possibly to put down a revolt. In any case, Duncan's death at the hands of Macbeth is recorded, hardly as the cold-hearted murder of the play, but most likely as the outcome of a battle. The details of the killing support the idea that it was purposeful and opportunistic, however - not accidental. Duncan was middle-aged (around thirty-nine) when he died, and had reigned for about five years, nine months.
Macbeth ruled for seventeen years, was generous to the church (which approved of him), and kept Scotland stable and secure enough in his power to make a pilgrimage to Rome in 1050. Reports describe his rule as tyrannical or prosperous (or both) and he was considered a far more effective ruler than his predecessor, Duncan.
Finally, Malcolm (Malcolm Canmore, Malcolm III) with his uncle Siward and support from the English king marched against Macbeth in 1054. Their victory was only partial, however, and Macbeth retained power in Moray and other territories. During this time, the people's alliegance began to turn back to Malcolm. Finally, Malcolm killed Macbeth in battle in 1057, securing his own kingship. Macbeth's death occurred seventeen years to the day from Duncan's murder, completing Malcolm's revenge of his father.
Concerning Banquo – his mere existence is questionable. He is said to be the ancestor of the House of Stuart, but some contend that he was fictional, only added later to give credibility and prestige to the 15th-century Scottish dynasty for fulfilling an ancient prophecy. Banquo, Thane of Lochaber, was brought into the story by Boece, who also originated the presence of Banquo's ghost.
Macduff is also mythological in nature, although his character may be based on other historical figures. The Earls of Fife would have taken their name from Duff, an ancestor, and may have held the territory in the 11th century. His invention, along with the destruction of his castle and family, is thanks to Fordun's account of the story in his Chronicle (c. 1363).
Images from Macbeth: Man and Myth