The term "Onanism" is sometimes used as a reference to personal indulgence, or excess. More commonly, it is used as an alternate word for masturbation. Though common, this particular use of the word "Onanism" is misleading. The Biblical story of Onan is not at all about masturbation, but exploitation and rebellion.
Onanism – What is it? Is it a sin?
In Genesis 38:8-10, Onan is commanded to follow the Law and provide a child for his brother's widow. This practice of a "levirate marriage" was meant to carry on the deceased man's family, giving his widow a legally-official heir to provide for her. Onan was willing to take advantage of the law in order to have sex with his sister-in-law, but purposefully withdrew early so he would not impregnate her. Whether he did this in order to give himself additional sexual access to her, or simply because he did not want to provide an heir for his brother, the Bible does not say.
What the Bible does say is that for this sin of exploitation and defiance, God killed Onan. Though some bring up Onan in conversations about masturbation, there is no biblical reason to do so. The events of Onan's story have no relation to masturbation whatsoever, other than the non-vaginal release of semen. Onan's story is also not applicable to the withdrawal method of birth control. Onan's sin was refusing to fulfill the law, acting disingenuously and selfishly toward his sister-in-law.
Masturbation raises many spiritual and ethical questions regarding lust. For that reason, it's a topic to which Christians ought to give careful consideration. The issue of masturbation has been discussed in other articles. Christian couples should also give careful consideration to family planning and birth control methods. We have articles on birth control here. "Onanism" in the particular sense of what Onan did in refusing to provide an heir for his brother as required by the law, was certainly sinful. However, it is a sin that does not apply to modern culture, other than in the sense of having a defiant or self-serving heart.
Is masturbation a sin according to the Bible?
Are wet dreams / nocturnal emissions sinful?
Can a person ever masturbate without it being a sin?
What does the Bible say about birth control?
Does God expect everyone to have children?
Truth about Sin