Why did David grab five stones when he went out to fight Goliath?

According to the story, David had total faith in God when he went to fight against Goliath, the giant. He picked up five stones because he had no way of knowing if he would be able to kill Goliath on his first try. David did what he could do to ensure his own capability in the face of a challenge.

The debate over the five stones is whether or not David trusted God. It would have been wrong for David not to have grabbed more than one stone. If David had just selected a single stone, he would have been putting God to a test.

"And David left his carriage in the hand of the keeper of the carriage, and ran into the army, and came and saluted his brethren. And as he talked with them, behold, there came up the champion, the Philistine of Gath, Goliath by name, out of the armies of the Philistines, and spake according to the same words: and David heard [them]. And all the men of Israel, when they saw the man, fled from him, and were sore afraid. And the men of Israel said, Have ye seen this man that is come up? surely to defy Israel is he come up: and it shall be, [that] the man who killeth him, the king will enrich him with great riches, and will give him his daughter, and make his father's house free in Israel. And David spake to the men that stood by him, saying, What shall be done to the man that killeth this Philistine, and taketh away the reproach from Israel? for who [is] this uncircumcised Philistine, that he should defy the armies of the living God?" (1 Sam. 17:22-26).

"And he took his staff in his hand, and chose him five smooth stones out of the brook, and put them in a shepherd's bag which he had, even in a scrip; and his sling [was] in his hand: and he drew near to the Philistine. And the Philistine came on and drew near unto David; and the man that bare the shield [went] before him. And when the Philistine looked about, and saw David, he disdained him: for he was [but] a youth, and ruddy, and of a fair countenance. And the Philistine said unto David, [Am] I a dog, that thou comest to me with staves? And the Philistine cursed David by his gods. And the Philistine said to David, Come to me, and I will give thy flesh unto the fowls of the air, and to the beasts of the field. Then said David to the Philistine, Thou comest to me with a sword, and with a spear, and with a shield: but I come to thee in the name of the LORD of hosts, the God of the armies of Israel, whom thou hast defied. This day will the LORD deliver thee into mine hand; and I will smite thee, and take thine head from thee; and I will give the carcasses of the host of the Philistines this day unto the fowls of the air, and to the wild beasts of the earth; that all the earth may know that there is a God in Israel. And all this assembly shall know that the LORD saveth not with sword and spear: for the battle [is] the LORD'S, and he will give you into our hands. And it came to pass, when the Philistine arose, and came and drew nigh to meet David, that David hasted, and ran toward the army to meet the Philistine. And David put his hand in his bag, and took thence a stone, and slang [it], and smote the Philistine in his forehead, that the stone sunk into his forehead; and he fell upon his face to the earth" (1 Sam. 17:40-49).