The Lord's anger burned against Israel and incited David to number Israel and Judah. Joab questioned why he would "delight in this thing." He and his commanders numbered 800,000 valiant men in Israel and 500,000 men in Judah who drew the sword (2 Sam. 24:1-9). Trust in human resources instead of God angers Him.
When David's heart troubled him after numbering the people, he told the Lord that he sinned greatly. He asked God to take away his iniquity for he acted foolishly. God instructed the prophet Gad to give David three consequences for his sin: seven years of famine in his land, flee three months before his foes pursued him or three days of pestilence. David's distress caused him to ask for the Lord's great mercies instead of falling into men's hands (2 Sam. 24:10-14). Confession of sin leads to Gods' mercy.
The Lord sent pestilence and 70,000 men died from Dan to Beersheba. The angel stretched out his hand to destroy Jerusalem but the Lord stopped the calamity. David said to the Lord that he had sinned and done wrong (2 Sam. 24:15-17). Take responsibility for your sin stops further consequences.
After Gad told David to construct an altar to the Lord, he wanted to buy the threshing floor of Araunah to build it so the plague would stop. Araunah offered up free oxen so David could do a burnt offering. He bought the threshing floor and oxen for 50 shekels of silver as he did not want to offer a burnt offering for nothing. David built an altar to the Lord and offered burnt and peace offerings. The Lord was moved by entreaty for the land and the plague stopped (2 Sam. 24:18-25). Costly obedience and intercession causes God to act.
Is there something that God wants you to surrender to Him at a cost because you are not seeking Him first (Matt. 6:33; Is. 55:1).