Then Satan stood against Israel and incited David to number Israel. So David said to Joab and the commanders of the army, "Go, number Israel, from Beersheba to Dan, and bring me a report, that I may know their number." But Joab said, "May the LORD add to his people a hundred times as many as they are! Are they not, my lord the king, all of them my lord's servants? Why then should my lord require this? Why should it be a cause of guilt for Israel?" But the king's word prevailed against Joab. So Joab departed and went throughout all Israel and came back to Jerusalem. And Joab gave the sum of the numbering of the people to David. In all Israel there were 1,100,000 men who drew the sword, and in Judah 470,000 who drew the sword. But he did not include Levi and Benjamin in the numbering, for the king's command was abhorrent to Joab.
But God was displeased with this thing, and he struck Israel. And David said to God, "I have sinned greatly in that I have done this thing. But now, please take away the iniquity of your servant, for I have acted very foolishly." And the LORD spoke to Gad, David's seer, saying, "Go and say to David, 'Thus says the LORD, Three things I offer you; choose one of them, that I may do it to you.'" So Gad came to David and said to him, "Thus says the LORD, 'Choose what you will: either three years of famine, or three months of devastation by your foes while the sword of your enemies overtakes you, or else three days of the sword of the LORD, pestilence on the land, with the angel of the LORD destroying throughout all the territory of Israel.' Now decide what answer I shall return to him who sent me." Then David said to Gad, "I am in great distress. Let me fall into the hand of the LORD, for his mercy is very great, but do not let me fall into the hand of man."
So the LORD sent a pestilence on Israel, and 70,000 men of Israel fell. And God sent the angel to Jerusalem to destroy it, but as he was about to destroy it, the LORD saw, and he relented from the calamity. And he said to the angel who was working destruction, "It is enough; now stay your hand." And the angel of the LORD was standing by the threshing floor of Ornan the Jebusite. And David lifted his eyes and saw the angel of the LORD standing between earth and heaven, and in his hand a drawn sword stretched out over Jerusalem. Then David and the elders, clothed in sackcloth, fell upon their faces. And David said to God, "Was it not I who gave command to number the people? It is I who have sinned and done great evil. But these sheep, what have they done? Please let your hand, O LORD my God, be against me and against my father's house. But do not let the plague be on your people."
Now the angel of the LORD had commanded Gad to say to David that David should go up and raise an altar to the LORD on the threshing floor of Ornan the Jebusite. So David went up at Gad's word, which he had spoken in the name of the LORD. Now Ornan was threshing wheat. He turned and saw the angel, and his four sons who were with him hid themselves. As David came to Ornan, Ornan looked and saw David and went out from the threshing floor and paid homage to David with his face to the ground. And David said to Ornan, "Give me the site of the threshing floor that I may build on it an altar to the LORD—give it to me at its full price—that the plague may be averted from the people." Then Ornan said to David, "Take it, and let my lord the king do what seems good to him. See, I give the oxen for burnt offerings and the threshing sledges for the wood and the wheat for a grain offering; I give it all." But King David said to Ornan, "No, but I will buy them for the full price. I will not take for the LORD what is yours, nor offer burnt offerings that cost me nothing." So David paid Ornan 600 shekels of gold by weight for the site.