In Acts 13:22, the Apostle Paul declares David was "a man after [God's] own heart" (Acts 13:22).

When David became Israel's reigning king, he obeyed God, "and he became more and more powerful, because the LORD God Almighty was with him."  (2 Samuel 5:3,4,10)  However, one spring evening David saw the naked Bathsheba, wife of Uriah, and lusted after her.  David should never have acted on his lust, but he let his fleshly wishes overpower his righteous heart.  Soon he committed adultery and conceived a baby with Bathsheba. As a cover-up, he arranged for Uriah's certain death on the battlefield.

Thus David was guilty of adultery and murder. To address these sins, God sent the prophet Nathan to confront David. The confrontation is recorded in 2 Samuel 12. David suddenly felt the full horror of his deeds.

Psalm 51 records the process of David’s repentance and subsequent restoration to fellowship with God. In a broader application, this psalm was written for our benefit, as well. Psalm 51 teaches us that even when we may commit terrible sins, these verses provide comfort and instruction for how to recover our relationship with our Heavenly Father.

In verses 1-4 David confesses his sin and begs for God's mercy. He knows God is a God of forgiveness and love. By acknowledging our sins, we develop a deeper, more heartfelt appreciation of God’s righteous judgments.

In verses 5 and 6, David acknowledges he was “sinful from the time my mother conceived me."  But he also recognizes God will teach him truth and wisdom.

Verses 7, 8, 9 –  The hyssop referred to in verse 7 was used in ceremonial cleansing (Leviticus 14:4), and the plant was known to have antiseptic properties.  David saw  sin’s contamination and wanted it washed away completely.  He refers to how the realization of his sin weighed on him so much, that he felt "crushed" and now begs for God's returned favor to lift that weight and give him "joy and gladness."

Then David sees that he must reconfirm his complete devotion to God, and he cries out, "Create in me a pure heart, O God."  He asks for a renewed, steadfast spirit, and the joy of the LORD to sustain him.  (Verses 10-12)

In verses 13-15, David acknowledges that God is his only salvation, and he desires to tell others about God’s grace and love.

Verses 16 and 17 are vital to all who want to please God.  Our Father is not interested in ceremonies performed only out of duty; what God wants is "a broken spirit, a broken and contrite heart."  This means we must give up trying to justify ourselves; we must realize that we can't be righteous in our own strength.  We must rely completely on God's grace (which in this age means accepting the sacrifice of Jesus on our behalf).  And then we must fully accept God's forgiveness and love, and lean on His mighty power to help us follow His Son.