2 Samuel 24:4-9
4-9Nevertheless, the king insisted, and so Joab and the army officers left the king to take a census of Israel. They crossed the Jordan and began with Aroer and the town in the canyon of the Gadites near Jazer, proceeded through Gilead, passed Hermon, then on to Dan, but detoured Sidon. They covered Fort Tyre and all the Hivite and Canaanite cities, and finally reached the Negev of Judah at Beersheba. They canvassed the whole country and after nine months and twenty days arrived back in Jerusalem. Joab gave the results of the census to the king: 800,000 able-bodied fighting men in Israel; in Judah 500,000.
10But when it was all done, David was overwhelmed with guilt because he had counted the people, replacing trust with statistics. And David prayed to God, "I have sinned badly in what I have just done. But now God forgive my guilt—I've been really stupid."