How old was John the Baptist when he died?

First we need to establish in what year John the Baptist died.
According to the canonical Gospels, John died shortly after Jesus began his ministry. According to tradition, this would place his death about 29 or 30 CE. However, the Jewish historian, Flavius Josephus, seems to place his death much later, at about 36 CE. (1)

Luke says that John was born a little before Jesus. In turn, Jesus was born during the reign of King Herod the Great, who died in April 4 BCE. In fact, Matthew seems to think that Jesus was born some years before the death of Herod.

Based on the above information, John was certainly at least 40 years old, and possibly much older. (1) Evidence from Josephus (Antiquities of the Jews Book XVIII)
Josephus places the marriage of Antipas to his brother's former wife, Herodias, at the same time as, or shortly after, the death of Philip II, who he says died in the twentieth year of the reign of Tiberius (34 CE). John was highly critical of this marriage, causing Antipas to fear that he would cause an insurrection:
Herod, who feared lest the great influence John had over the people might put it into his power and inclination to raise a rebellion, (for they seemed ready to do any thing he should advise) thought it best, by putting him to death, to prevent any mischief he might cause, and not bring himself into difficulties, by sparing a man who might make him repent of it when it would be too late. Accordingly he was sent a prisoner, out of Herod's suspicious temper, to Macherus, the castle I before mentioned, and was there put to death.
Josephus makes it clear that Antipas intended to execute John, and it seems most improbable that he would long delay the execution if he feared an insurrection by John's supporters. The execution would have quickly followed the imprisonment.
Additionally, King Aretas attacked and defeated Antipas in 36 CE in revenge for the slight to his daughter, whom Antipas divorced in order to marry Herodias. We can expect a one or two year delay during which the news reached Aretas and he considered a diplomatic solution or demanded compensation, then raised an army, but an angry father is not likely to have waited ten years to take action.

Some of the Jews believed that Antipas' defeat was divine retribution for his execution of John:Now the Jews had an opinion that the destruction of this army was sent as a punishment upon Herod, and a mark of God's displeasure to him.
This association makes it most likely that John's death was a quite recent event at the time of the defeat - closer in time to the battle than to the wedding, and certainly not something that occurred 8 or 10 years earlier.

Another answer:
Josephus adds the additional detail that the military defeat of Herod, known to have occurred in 36 AD was seen by many Jews as a direct punishment by God for Herod's execution of John. Obviously there is not sufficient time for Jesus to have been crucified in 36 as well as this defeat. History shows that both Pilate and Herod had other things going on in 36 which indicate the crucifixion was in the past by a number of years.

In the light of the Gospel record, it would seem likely that John was indeed around 36 or possibly even 39 years of age when he was executed in the year 32 AD, since we also know John was born before Jesus, who was born before 4 BC possibly down to 6 BC.

Summary: John was likely around 36 to 38 (a more likely age) when he was executed.
The Jewish historian, Josephus tells us that John the Baptist was executed at Macherus approximately 36 CE. And according to Luke's Gospel, John was born during the reign of King Herod the Great, who died in 4 BCE. This would mean that John must have been at least 40 years old when he died.