The question - "When were the gospels written?" - has been hotly debated over the centuries and for good reason, since the answer impacts their perceived accuracy. If the gospels were written while Jesus' disciples were still alive, they are first-hand accounts written or dictated by eyewitnesses. But if the gospels were written centuries after Jesus' earthly ministry, then their writers were not eyewitnesses who can personally validate the accuracy of what they wrote (see Golgotha and Jesus' Tomb).
So when were the gospels written?
Below is a methodical deduction of the timeline that answers this question.
In AD 62, the Apostle Paul was martyred in Rome after two years of imprisonment. In AD 64, Emperor Nero set fire to Rome and blamed Christians to launch his persecution of the early church. In AD 70, the Roman general Titus sacked Jerusalem. All three events were major milestones in the history of the early church.
The Book of Acts, which immediately follows the four gospels of Matthew, Mark, Luke and John, records the history of the early church. Acts was written by a doctor named Luke who served as Paul's travel partner and secretary. Since Acts mentions none of the three milestones above and ends after mentioning Paul's two year imprisonment in Rome, Acts must have been written just before Paul was martyred in AD 62.
The first chapter of Acts opens with the words, "The former account I made, O Theophilus, of all that Jesus began both to do and teach, until the day in which He was taken up, after He through the Holy Spirit had given commandments to the apostles whom He had chosen..." (Act 1:1-2)
The "former account" Luke mentions in Acts is what we call today the Gospel of Luke, also written to Theophilus: "Inasmuch as many have taken in hand to set in order a narrative of those things which have been fulfilled among us, just as those who from the beginning were eyewitnesses and ministers of the word delivered them to us, it seemed good to me also, having had perfect understanding of all things from the very first, to write to you an orderly account, most excellent Theophilus, that you may know the certainty of those things in which you were instructed." (Luke 1:1-4)
The delivered eyewitness accounts that Luke mentions above are the Gospels of Mark and Matthew. The latter was written by Matthew, the tax collector who was one of Jesus' twelve Apostles, while the former was written by Mark, who accompanied Peter and recorded what he preached. Among the four gospels, Mark's gospel is generally considered to have been written first.
If a 2-4 year gap is estimated between Acts and the Gospel of Luke, this would mean the Gospel of Luke was written in AD 58-60. If another 2-4 years separate the Gospel of Luke and the Gospel of Matthew, this would mean the Gospel of Matthew was written in AD 54-58. And if another 2-4 years separate the Gospel of Matthew and the Gospel of Mark, it would mean the Gospel of Mark was written in AD 50-56. In other words, three of the four gospels could be deduced to have been written by Jesus' disciples or their secretaries only about 20 to 30 years after they last saw Jesus, and they were read by people who had witnessed the events recorded and could personally confirm their details.
Are those details faithfully preserved in today's Bibles?
The New Testament was originally written in Greek, and the earliest Greek manuscripts discovered date to about AD 150, which is only about a century after Jesus. Moreover, the number of such ancient Greek manuscripts discovered to date exceeds 5,800.
Two points can be made.
First, our knowledge of the history of the early Roman Empire is based largely on The Annals of the Roman Empire, written by the Roman historian Tacitus in AD 116. Only two manuscripts of that in the original language exist today. One dates from the 9th century and the other from the 11th century. In other words, details of the early Roman Empire rely on two manuscripts written about ten centuries after the original, while the details of Jesus' earthly ministry stand on over 5,800 manuscripts that date from as early as about one century after the originals; there is far stronger evidence for the details of Jesus' earthly ministry than for the early history of the Roman Empire.
Second, these 5,800+ manuscripts were discovered in a vast area that stretches from the Middle East to North Africa to Western Europe. Imagine a class of school children playing a game of whisper phone. The teacher whispers, "Mary gave a crayon to Charlie" to two students, and they each whisper to two other students, and so on. If after five generations of whispers a student in one corner of the classroom reports, "Mary gave a crayon to Charlie," while a student in another corner reports, "Mary and Charlie fought over a pencil," the class won’t know what the teacher originally had whispered. But if two students in distant corners say exactly same thing, the original message can be deduced without having been heard by everyone.
What's the point?
The original manuscripts disintegrated long ago from having passed from hand to hand to be read and copied, but almost all (95-99%) of the 5,800+ manuscripts discovered to date say in effect, "Mary gave a crayon to Charlie." So we can deduce that what was originally written is what is in those 5,800+ manuscripts, and today’s gospels are translated directly from them.
For more, see Science And Bible.