Before one can stop sinning, I think it would be good to understand well what sin really means. I have understood sin means that person rejects God, or lives apart from God. I believe so because of these:
He who does righteousness is righteous, even as he is righteous. He who sins is of the devil, for the devil has been sinning from the beginning. To this end the Son of God was revealed, that he might destroy the works of the devil. Whoever is born of God doesn't commit sin, because his seed remains in him; and he can't sin, because he is born of God. In this the children of God are revealed, and the children of the devil. Whoever doesn't do righteousness is not of God, neither is he who doesn't love his brother.
1 John 3:7-10
Now that no man is justified by the law before God is evident, for, "The righteous will live by faith.
Galatians 3:11
But the righteous will live by faith. If he shrinks back, my soul has no pleasure in him.
Hebrews 10:38
Sin is the opposite of righteous. And righteous lives, because he is faithful/loyal to God. that is why I believe sin is unfaithfulness to God, or that person rejects God. And this means, no matter what happens, don’t reject God and you don’t have sin. If you reject God because of masturbation for example, then it has become sin for you. But obviously, this doesn’t tell is it good or bad. Good or bad can depend on many matters. I don’t think Bible says it is wrong, but I think this basic rule is good for many unclear matters:
”All things are lawful for me," but not all things are expedient. "All things are lawful for me," but I will not be brought under the power of anything.
1 Corinthians 6:12
"All things are lawful for me," but not all things are profitable. "All things are lawful for me," but not all things build up."
1 Corinthians 10:23
I think it is not good if for example the desire rules you and becomes greater than God for you.
And in any case, I think it can be forgiven. And one way to show that you remain faithful to God is that you ask forgiveness, if you have done something wrongly. I believe being righteous doesn’t mean that person is perfect, it means person is loyal to God and when loyal person has done wrongly, he asks forgiveness like in this example:
"Two men went up into the temple to pray; one was a Pharisee, and the other was a tax collector. The Pharisee stood and prayed to himself like this: 'God, I thank you, that I am not like the rest of men, extortioners, unrighteous, adulterers, or even like this tax collector. I fast twice a week. I give tithes of all that I get.' But the tax collector, standing far away, wouldn't even lift up his eyes to heaven, but beat his breast, saying, 'God, be merciful to me, a sinner!' I tell you, this man went down to his house justified rather than the other; for everyone who exalts himself will be humbled, but he who humbles himself will be exalted."
Luke 18:10-14
But then, how to stop sinning, how to not reject God? I believe that happens when you learn to know God and love Him. When you love Him, you don’t want to reject Him.