This is the 60th question posed in the Heidelberg Catechism, published in 1563. Here’s the wonderful answer:
Only by true faith in Jesus Christ.
Even though my conscience accuses me of having grievously sinned against all God’s commandments and of never having kept any of them, and even though I am still inclined toward all evil,
nevertheless, without my deserving it at all, out of sheer grace, God grants and credits to me the perfect satisfaction, righteousness, and holiness of Christ,
as if I had never sinned nor been a sinner, as if I had been as perfectly obedient as Christ was obedient for me.
All I need to do is to accept this gift of God with a believing heart.
This is as relevant to us on our best days as much as on our worst days. As Jerry Bridges says, “Your worst days are never so bad that you are beyond the reach of God’s grace. And your best days are never so good that you are beyond the need of God’s grace” (Discipline of Grace, 18). Praise God from whom all blessings flow; look to the cross from where all blessings flow.