Justification is the act in which God declares us righteous. This happens the moment we trust in Christ for salvation, and so it is based on our faith and not any of our works. God can declare sinners righteous because Christ died for our sins and because Christ gives us His own righteous status when we believe in Him. If Christ is righteous, the so are those united to Him by faith.