Bible Answer

How many years of famine did God offer to David for his sin?

In 2 Samuel 24 and 1 Chronicles 21, I find conflicting accounts of the story of David numbering his troops. Did the Lord decree three years of famine or seven years of famine for David's sin? 
 

In 2 Samuel 24 and in 1 Chronicles 21, we're told that David sinned by numbering his forces against God's wishes. In response to David's sin, the Lord offers David a choice of how he would be punished. As you pointed out, the possible punishments recorded in these two accounts differ. In 2 Samuel 24, David is offered seven years of famine while in 1 Chronicles 21 David is offered three years of famine. Is this a contradiciton?

In reality, both of these statements are correct. In the account recorded in 2 Samuel, the writer informs us in an earlier chapter (Chapter 21) that the land of Israel had already experienced three years of a famine before David committed his sin:

2Sam. 21:1 Now there was a famine in the days of David for three years, year after year; and David sought the presence of the LORD. And the LORD said, “It is for Saul and his bloody house, because he put the Gibeonites to death.”
 

As we reach chapter 24 of 2 Samuel, David sins by sending Joab throughout the land of Israel to count the number of David's forces. The counting takes more than nine months, according to 2 Samuel 24:8, which means the famine is now approaching the fourth year. This is the moment when God offers David a choice of punishment for his sin. In 2 Samuel 24, the punishment is recorded as seven years, while in 1 Chronicles 21 the punishment is described as three years.

Since the writer of 2 Samuel has already informed his readers of the ongoing four-year famine, he described David's punishment as seven years of famine, since this punishment would have added three more years to the four years already past. The writer wanted his readers to understand that had David chosen this option, he would have burdened the people of Israel with a total of seven years of famine.

Turning to the same account recorded in 1 Chronicles, we find no mention of the ongoing four years of famine in the land prior to David's sin. Since the author of 1 Chronicles had never mentioned this detail, he recorded the length of David's punishment as three years of famine.

So were there seven years of famine or only three? The answer is BOTH. Had David chosen this option, there would have been seven years of famine altogether in Israel, because four years had already occurred, and the punishment offered to David was three additional years of famine.