We are glad that you have come to us with a heart seeking forgiveness. First, let's address the issue at hand. Masturbation is a sin in and of itself since it involves lust in the heart. Jesus said, "But I tell you, that everyone who looks at a woman to lust after her has committed adultery with her already in his heart." (Matthew 5:28 WEB) Sinful thoughts and fantasies are also included in this.
Another issue with masturbation is that it is selfish and is not the purpose for which God created sex. God designed sex to be shared and enjoyed in a holy marriage between a man and a woman.
You are right to seek forgiveness. The Bible tells us, "If we confess our sins, he is faithful and righteous to forgive us the sins, and to cleanse us from all unrighteousness." (1 John 1:9 WEB) So let us pray for forgiveness and for strength to resist temptation.
Dear Jesus,
We come before You, confessing and repenting of the sin of masturbation and sinful thoughts. We ask for Your forgiveness, knowing that You are faithful and just to forgive us our sins and to cleanse us from all unrighteousness. We also pray for strength and self-control to resist these temptations in the future. Help us to take every thought captive to obey Christ. (2 Corinthians 10:5 WEB) Guide us in the way of purity and holiness, as You have called us to be. In Jesus' name, we pray. Amen.
Remember, God not only offers forgiveness but also the power to overcome sin. "No temptation has taken you except what is common to man. God is faithful, who will not allow you to be tempted above what you are able, but will with the temptation also make the way of escape, that you may be able to endure it." (1 Corinthians 10:13 WEB)
Stand strong in the Lord, and keep pursuing holiness. As you seek to please Him in all things, God will continue to shape you into the image of Christ.
The fact that you are asking God to forgive you is a very positive step. This is an area you need to be very open with God about. He is the one that can help you get the victory. But it is only by the name of Jesus that we have access to God. Therefore, it is essential to address your prayers to Jesus.
You may need to seek out a local church and ask for one on one counseling with your Pastor, and they can help you get the victory. You can also talk to your Pastor about being baptized if you have not done so. Jesus called this being born again. In fact, Jesus said unless a man is born again, he cannot see the kingdom of God.
Also, you may wish to consider a book such as "Every Man's Battle" by Stephen Arterburn. It discusses this issue and is very helpful to most people.
As far as lust of the heart, the Bible tells us to have pure thoughts and not to lust after what we do not have. This is an area you definitely need to ask God to help you with. You may also need to avoid situations that cause you to lust in your heart.
God loves you and we all need His love, guidance, and forgiveness. God Bless you.