The parallel account of the incident surrounding the census reveals it was Satan who incited David to take the census: “Satan rose up against Israel and incited David to take a census of Israel” (1 Chronicles 21:1). However, the wording of 2 Samuel 24:1 says that it was God who “moved David” to take the census. This discrepancy can be explained by the understanding that sometimes God sovereignly permits Satan to act in order to achieve His purposes. God uses Satan in various ways, among them the refining, disciplining and purification of disobedient believers (Luke 22:31-32; 1 Corinthians 5:1-5; 2 Corinthians 12:7-10). Such is the case with David. God allowed Satan to tempt him, and David sinned, revealing his pride and allowing God to deal with him for it.
As to why God was angry at David, in those times, a man only had the right to count or number what belonged to him. Israel did not belong to David; Israel belonged to God. In Exodus 30:12 God told Moses, “When you take a census of the Israelites to count them, each one must pay the LORD a ransom for his life at the time he is counted. Then no plague will come on them when you number them.” It was up to God to command a census, and if David counted he should only do it at God's command, receiving a ransom to "atone" for the counting. This is why God was angry again with Israel and is also why David was “conscience-stricken” after he counted Israel. David knew it was wrong and begged God to take away the guilt of his sin (2 Samuel 24:10).