Check the difference between mortal and venial sins. When you commit venial sins you remain in a state of grace. When you commit mortal sins you do not.
From the Catechism:
[1855] Mortal Sin destroys charity in the heart of man by a grave violation of God’s law; it turns man away from God… by preferring an inferior good to him. Venial sin allows charity to subsist, though it offends and wounds it.
[1861] Mortal sin… results in… the privation of sanctifying grace, that is, of the state of grace. If it is not redeemed by repentance and God’s forgiveness, it causes exclusion from Christ’s kingdom and the eternal death of hell…
[1862] One commits venial sin when, in a less serious matter, he does not observe the standard prescribed by the moral law, or when he disobeys the moral law in a grave matter, but without full knowledge or complete consent.
[1863] Venial sin weakens charity… and… merits temporal punishment. Deliberate and unrepented venial sin disposes us little by little to commit mortal sin. However, venial sin does not break the covenant with God. With God’s grace, it is humanly reparable. “Venial sin does not deprive the sinner of sanctifying grace, friendship with God, charity, and consequently, eternal happiness.”
I quoted the most significant parts of these paragraphs relative to your question. See the Catechism for the complete paragraphs.