Since the NFL's existence, but especially in the 1950's and 60's, players started celebrating after they reached the end zone. After all, scoring a touchdown was hard work and players wanted to celebrate. The most well known touchdown celebration is the football spike. It involves the player slamming the ball down hard on the turf and then walking away.
In 2007, the NFL made spiking of the ball, except for in the end zone an infraction that would cost the team five yards. The rule was instated to cut down on delay of game and to limit player celebrations except for after a touchdown.
Spiking the Ball to Stop the Clock
A team intentionally spikes the ball to stop the clock when they are short on time and have little or no timeouts. In football, the only way you can stop the clock is by calling a timeout, running out of bounds, or by spiking the ball. If a team wishes to stop the clock by spiking the ball, the team will line up at the line of scrimmage like they always do. The center will hike the ball to the quarterback, and the quarterback will immediately spike the ball into the ground.
Intentional grounding is when the quarterback drops back with the intention of passing the football, but "throws the ball away" in order to prevent a sack or lack of open receivers downfield. "Throwing the ball away" can range from a spike to throwing the ball twenty yards out of bounds. Basically there needs to be proof that the quarterback threw the ball with no purpose of trying to hit a receiver.
When "Throwing the Ball Away" is Legal
If the quarterback escapes the pocket, which is the distance between the left and right offensive tackles, then the quarterback is now free to throw the ball away purposely and not receive an intentional grounding penalty.