In order to be saved we need to acknowledge before God that we are sinners. The word sin really means a short coming. Romans 3:23 says, "all have sinned and come short of the glory of God". Imagine I had a bow and arrow in my hand, and was aiming to hit a bulls-eye on a target. No matter how hard I try, I can never quite hit the bulls-eye. My arrows keep falling short. God's bulls-eye is His commandments. My arrows are like my own efforts to try to please God. They will never meet God's standard, which is complete perfection (Revelation 21:27). The Bible says even our best efforts for God are sin, because they fall far short of His perfect standard (Isaiah 64:6). So there is absolutely nothing we can do to please God through our own efforts.
Our good works cannot please God, nor can they offer recompense to God for our sins (Galatians 2:16). Imagine I had been stealing goods from a particular shopkeeper. One day I happened to be unlucky, and he caught me in the act of stealing his goods. He threatened to report me to the police. I plead with him not to turn me in. I tell him, "Please forgive me, I will pay for everything from now on!" Will he forgive me? If he is to be just then he cannot, for the law demands a recompence. I must repay him for all the goods I have stolen before I can be forgiven. This is what our sin against God is like. Even after we realize we are sinners, if we try our best to be good from now on, this is not sufficient to please God. For the Bible says that God requires that which was done in the past (Ecclesiastes 3:15). Now we have a problem. There is no way for me to repay God for my sins. I cannot travel back in time and change what I have done. It is in the past. If I had a rich friend, he could pay my debt to the shopkeeper for me. The stolen goods have value and the value of the goods can be repaid. But my sins cannot be repaid. I must face God's judgement for my sin. The only way I can be forgiven is if someone takes the punishment for my sins instead of me.
That was what Jesus Christ did on the cross. He is the Mediator between God and men (1st Timothy 2:5). He was God, and so was able to live a sinless life and offer Himself up as a perfect sacrifice for our sins (John 1:29). He was also man, so he was able to take my place on the cross. When Jesus was on the cross, God took my sins from me, and placed them upon His own Son (1st Peter 2:24). Because Jesus Christ has already born God's punishment for my sins upon the cross, I can go free. We sometimes sing a hymn that says, "Payment God will not twice demand, first at my bleeding Surety's hand, and then again at mine". Jesus Christ was my 'Surety', my 'Guarantor' to God for my debt of sin. Because Jesus Christ has paid the penalty for my sins, there is nothing more for me to pay and I can be forgiven.
God's free gift of salvation is available for all (Romans 6:23, 1st John 2:2), but in order to be saved we must take it for ourselves. There are many people that believe that Jesus Christ died upon the cross for the sins of the whole world. But as far as they are personally concerned, they are still trying to obtain favour with God through their own good works. Will God let them into heaven? If He is to be just then He cannot, for His law demands a recompence. If their sins remain unforgiven, they will not get into heaven (John 8:21-24). Although God's offer of salvation was available to them, they did not take it for themselves. They were depending on their own righteousness to recompence God, which can never be sufficient. You need to make God's offer of salvation personal for yourself. Believe that Jesus Christ bore the punishment for your sins when He died upon the cross. And God has promised that all who believe on His Son for salvation shall have everlasting life (John 3:16).