What does the Bible say about this? Is it a sin?
The Bible does not mention masturbation by name. That means we must ask some questions to apply the appropriate principles from God's Word to find His perspective on the issue.
It's obvious God created sex to be enjoyable, but what is the setting He upholds as the place for sex to occur? It's always in marriage according to what we find in the Bible. Sex outside of marriage, whether with someone who is single (called fornication) or someone who is married to someone else (called adultery), is always condemned (see 1 Corinthians 6:18 and Galatians 5:19-21). In addition, Christ said that even looking on a woman with the intent of wanting to have sex with her is a violation of the commandment against adultery (Matthew 5:27-28). So God clearly teaches that sex belongs in marriage, not outside of it.
Sex is intended to be pleasurable, but it is obviously intended by God to be a pleasurable act that is shared between a husband and a wife. It forms a "pleasure bond," as some have described it, that helps emotionally unite the two people.
When you contrast that with masturbation (which is strictly for the pleasure of one person, whether male or female) it is obvious masturbation is outside of God's intent. It focuses on pleasing the self instead of a mate and is not the use of sex that brings the best long-term results in our lives.
As for whether masturbation is a sin or not, understanding the definition of sin can help us make that determination. One of the definitions of sin is "to miss the mark" (Vine's Expository Dictionary, art. "Sin"). Since masturbation misses the mark of what God intends for us, it is sin.