When did Shakespeare write King John and which stories inspired the play?
The Life and Death of King John is believed to have been written in the mid-1590s, although it did not appear in print until the First Folio of 1623. That text is thought to have come from a 1596 manuscript subsequently copied by scribes in 1609 and 1623. This may explain some of the play's textual problems that have to be untangled by editors and directors, such as in the character of Hubert, who may also be an unnamed citizen from earlier in the play.
King John is first mentioned as a Shakespeare play in 1598, in the Palladis Tamia of Francis Meres, which includes accounts of some of Shakespeare’s poems and early plays. Because of some of the vocabulary and poetic devices used, it has been dated as possibly from 1596, in between Richard II (the only other Shakespeare play written entirely in verse) and Henry IV Part I.
The anonymously-written history play The Troublesome Reign of King John (1589) shares many similarities to King John, with some discussion about which may have come first, whether Shakespeare wrote both, or if they are in fact different versions of the same play. The most widely-held view is that The Troublesome Reign is the earlier play and was used as a source for King John. When the reprint of The Troublesome Reign in 1622 announced that it was "Written by W. Sh.", this is generally seen as a ploy to help generate sales.
Other potential sources include Holinshed’s Chronicles (a comprehensive three-volume history of Britain often referenced by Shakespeare for his Histories) and Foxe’s Book of Martyrs. While the story is not changed from the source material, the dialogue and themes are Shakespeare’s own.