"Then David said to Nathan, 'I have sinned against the Lord.' Nathan replied, 'The Lord has taken away your sin. You are not going to die. But because by doing this you have made the enemies of the Lord show utter contempt, the son born to you will die'” (2 Samuel 12:13-14).
You can read the complete story of David’s awful sins in 2 Samuel 11-12. David violated these commands: “You shall not covet your neighbor’s wife,” “You shall not commit adultery,” “You shall not murder.” To hide his adultery, David called Uriah home from battle so Bathsheba’s pregnancy would be attributed to him. The lie did not work—Uriah was too honorable. He returned to Jerusalem, but refused to go home while his men remained on the battlefield. The next day David gave a dinner for Uriah and made him drunk. He still did not go home, so David had him killed and took his wife for himself.
David did not confess these sins. He was still hiding them (or thought he was) when he was confronted by Nathan the prophet. Before David confessed, Nathan prophesied awful consequences. After David confessed, he prophesied another consequence. David was forgiven, but the consequences still came. The baby son died. One of his other sons raped one of his daughters. Another son killed the son who raped the daughter. That son was exiled. He returned from exile, conspired against David, and openly committed adultery with his father’s concubines; then he was killed. These were the consequences of David’s sin.
How do we know that David was forgiven?
"Then I acknowledged my sin to you and did not cover up my iniquity. I said, 'I will confess my transgressions to the Lord' and you forgave the guilt of my sin" (Psalm 32:5).
"Against you, you only, have I sinned and done what is evil in your sight, so that you are proved right when you speak and justified when you judge…Cleanse me with hyssop, and I will be clean; wash me, and I will be whiter than snow. Let me hear joy and gladness; let the bones you have crushed rejoice. Hide your face from my sins and blot out all my iniquity. Create in me a pure heart, O God, and renew a steadfast spirit within me. Do not cast me from your presence or take your Holy Spirit from me. Restore to me the joy of your salvation and grant me a willing spirit, to sustain me…Save me from bloodguilt, O God, the God who saves me, and my tongue will sing of your righteousness…You do not delight in sacrifice, or I would bring it; you do not take pleasure in burnt offerings. The sacrifices of God are a broken spirit; a broken and contrite heart, O God, you will not despise" (Psalm 51:4, 7-12, 14, 16-17).
David did not minimize his sins like Saul had minimized his (1 Samuel 15). He confessed and counted on God’s great mercy, love, and compassion. David knew that he had forfeited his kingdom just as Saul had done:
"Now the Spirit of the LORD had departed from Saul…" (1 Samuel 16:14).
"Cast me not away from thy presence; and take not thy holy spirit from me" (Psalm 51:11).
When the prophet Samuel confronted Saul, Saul responded by making excuses and trying to shift the blame. When David was confronted, he made no excuses. He repented and confessed, and the Lord forgave him. He was allowed to keep his kingdom. David still had other consequences to face, but he had the joy of forgiven sins.