So the king said to Joab and the commanders of the army, who were with him, "Go through all the tribes of Israel, from Dan to Beer-sheba, and take a census of the people, so that I may know how many there are."
But Joab said to the king, "May the LORD your God increase the number of the people a hundredfold, while the eyes of my lord the king can still see it! But why does my lord the king want to do this?"
But the king's word prevailed against Joab and the commanders of the army. So Joab and the commanders of the army went out from the presence of the king to take a census of the people of Israel.
Joab reported to the king the number of those who had been recorded: in Israel there were eight hundred thousand soldiers able to draw the sword, and those of Judah were five hundred thousand.
But afterward, David was stricken to the heart because he had numbered the people. David said to the LORD, "I have sinned greatly in what I have done. But now, O LORD, I pray you, take away the guilt of your servant; for I have done very foolishly."
So Gad came to David and told him; he asked him, "Shall three years of famine come to you on your land? Or will you flee three months before your foes while they pursue you? Or shall there be three days' pestilence in your land? Now consider, and decide what answer I shall return to the one who sent me."
But when the angel stretched out his hand toward Jerusalem to destroy it, the LORD relented concerning the evil, and said to the angel who was bringing destruction among the people, "It is enough; now stay your hand." The angel of the LORD was then by the threshing floor of Araunah the Jebusite.
When David saw the angel who was destroying the people, he said to the LORD, "I alone have sinned, and I alone have done wickedly; but these sheep, what have they done? Let your hand, I pray, be against me and against my father's house."
When Araunah looked down, he saw the king and his servants coming toward him; and Araunah went out and prostrated himself before the king with his face to the ground.
Araunah said, "Why has my lord the king come to his servant?" David said, "To buy the threshing floor from you in order to build an altar to the LORD, so that the plague may be averted from the people."
Then Araunah said to David, "Let my lord the king take and offer up what seems good to him; here are the oxen for the burnt offering, and the threshing sledges and the yokes of the oxen for the wood.
But the king said to Araunah, "No, but I will buy them from you for a price; I will not offer burnt offerings to the LORD my God that cost me nothing." So David bought the threshing floor and the oxen for fifty shekels of silver.
David built there an altar to the LORD, and offered burnt offerings and offerings of well-being. So the LORD answered his supplication for the land, and the plague was averted from Israel.