This is a very difficult issue. And for someone trapped in the chains of sexual sin, there is no easy answer - but there is the stunning grace of God for freedom.
From my other answer, for context:
I would answer this question by starting with another question: Do you
want to live your life seeing how close you can get to sin without
actually crossing the line? Are you motivated to be the most Godly
person you can be (growing daily in Christ-likeness), or are you
motivated to "get away with" as much as possible without actually
going to hell?
Masturbation is a tricky question, since the Bible says little, if anything, about it specifically, and there's no other person involved. But we can turn my aforementioned question on ourselves and arrive at "is masturbating bringing me closer to God, respecting myself as a person and expressing pure Godly love?" (We can also direct the original question toward the naked object of our lust; I never did meet anyone who masturbated more than very occasionally without external "assistance" of a pornographic nature either in their head or their other hand). If we answer that honestly, the conclusion seems apparent.
In my experience, people engage in masturbation far more for emotional reasons and self-esteem issues than for physical needs. The need for affection can be met healthily in many other ways than this. The myriad of sayings and research about the benefits of physical contact (like hugs) did not originate in a vacuum.
FWIW, the teaching by which God brought me freedom after many years of chains was The Theology of the Body from John Paul II* for which Christopher West has an introductory book and a CD series which may be downloaded in MP3 format at no cost.
[*] Full disclosure: I am not a Catholic, rather a Pentecostal protestant. But I have a tremendous respect for the Catholic church and her people and consider them to be fellow believers. Experiencing a tremendous victory in my life via JP II's teaching contributes greatly to this.
Pacerier asked: "When it comes to God's view of sin, white is white and black is black. There's no gray areas. What I'm trying to say is that there's no such thing as being close to crossing the line. You either cross or you don't."
It's not that simple. Based on what the bible says, engaging in sexual intercourse when unmarried seems to me to be clearly a sin, while kissing one's girlfriend seems equally clearly not, although refraining from kissing until marriage may be even better. Somewhere in between there is the "line". Is masturbation a sin? Some would argue "yes", some "no", and some "it depends on the heart attitude and motivation".
My point is that regardless of the answer, it is far better to desire to be like Christ, and have an attitude that avoids "all appearance of evil". The question becomes, not "what action is permissible", but rather "what action is best".
As St. Paul said, "not all things are beneficial":
1 Cor 6:12-18 (NIV)
12 “I have the right to do anything,” you say — but not everything is beneficial. “I have the right to do anything” — but I will not be mastered by anything. 13 You say, “Food for the stomach and the stomach for food, and God will destroy them both.” The body, however, is not meant for sexual immorality but for the Lord, and the Lord for the body. 14 By his power God raised the Lord from the dead, and he will raise us also. 15 Do you not know that your bodies are members of Christ himself? Shall I then take the members of Christ and unite them with a prostitute? Never! 16 Do you not know that he who unites himself with a prostitute is one with her in body? For it is said, “The two will become one flesh.” 17 But whoever is united with the Lord is one with him in spirit.
18 Flee from sexual immorality. All other sins a person commits are outside the body, but whoever sins sexually, sins against their own body. 19 Do you not know that your bodies are temples of the Holy Spirit, who is in you, whom you have received from God? You are not your own; 20 you were bought at a price. Therefore honor God with your bodies.
For myself, personally, being free and remaining far away for the line of sexual immorality seems better than seeking to get as close to that line as I can. Thus for me, having received real victory over masturbation such that it's simply a non-issue in my life, I have no desire to return to that bondage, even if it could be somehow done without sinning. Other people may come to a different place, and I don't have a problem with that.