The history of masturbation describes broad changes in society concerning the ethics, social attitudes, scientific study, and artistic depiction of masturbation over the history of sexuality.
 The sexual stimulation of one's own genitals has been 
interpreted variously by different religions, and has been the subject of legislation, social controversy, activism, as well as intellectual study in sexology.
Social views regarding masturbation taboo have varied greatly in different cultures, and over history.
 There are depictions of male and female masturbation in prehistoric rock paintings around the world. Most early people seem to have connected human sexuality with abundance in nature. A clay figurine of the 4th millennium BC from a temple site on the island of Malta, depicts a woman masturbating. However, in the ancient world, depictions of male masturbation are far more common.
 From the earliest records, the ancient Sumerians had very relaxed attitudes toward sex. The Sumerians widely believed that masturbation enhanced sexual potency, both for men and for women, and they frequently engaged in it, both alone and with their partners. Men would often use puru-oil, a special oil probably mixed with pulverized iron ore intended to enhance friction. Masturbation was also an act of creation and, in Sumerian mythology, the god Enki was believed to have created the Tigris and Euphrates rivers by masturbating and ejaculating into their empty riverbeds.
 Male masturbation was an even more important image in ancient Egypt: when performed by a god it could be considered a creative or magical act: the god Atum was believed to have created the universe by masturbating to ejaculation.
 
Unlike the Sumerians and ancient Egyptians, the ancient Greeks regarded masturbation as uncivilized, suitable for slaves, barbarians and women. Haaretz columnist Terry Madenholm, explains:  There is a hint in the terminology as to why the practice was considered indecent. The most commonly used verb for masturbation is "to soften" (dephesthai), while for most Greeks, male sexuality was essentially about power dynamics. In bed, it all came down to active versus passive. Playing with oneself was seen as an act of passivity, good enough for the low-status men and the rest of the miserables lacking enkratia (self-control). A respected member of society, meaning a "real man", could only play an active role in bed, that of the "penetrator"; hence, masturbating (or performing fellatio or cunnilingus) was viewed as an act of self-emasculation.  Most information about masturbation in ancient Greece comes from surviving works of ancient Greek comedy and pottery. Masturbation is frequently referenced in the surviving comedies of Aristophanes, which are the most important sources of information on ancient Greek views on the subject. In ancient Greek pottery, satyrs are often depicted masturbating.
 According to the Lives and Opinions of Eminent Philosophers by the third-century AD biographer Diogenes Laërtius, Diogenes of Sinope, the fourth-century BC Cynic philosopher, often masturbated in public, which was considered scandalous. When people confronted him over this, he would say, "If only it were as easy to banish hunger by rubbing my belly." Diogenes, speaking in jest, credited the god Hermes with its invention: he allegedly took pity on his son Pan, who was pining for Echo but unable to seduce her, and taught him the trick of masturbation in order to relieve his suffering. Pan in his turn taught the habit to young shepherds.
 Masturbation is little noted in the sources for ancient Roman sexuality. The poet Martial considers it an inferior form of sexual release resorted to by slaves. Aulus Gellius, a Latin writer of the second century A.D., claims that the fragment of Empedocles "O wretches, utter wretches, from beans withhold your hands" refers to the testicles symbolically, trying to keep men away "from excess in venery". Though infrequently mentioned, masturbation was a longstanding theme in Latin satire, appearing in one of the few surviving fragments of Lucilius, Rome's earliest practitioner of the genre. The Romans preferred the left hand for masturbation.
 Within the African Congo Basin, the Aka and Ngandu ethnic groups all lack a word for masturbation in their languages and are confused by the concept of masturbation.
 Several medical papers were written on insanity as a result of masturbation, and this was written as a reason for admission when a person was confined in a hospital. A doctor named J W Robertson tried to describe the differences between different types of masturbation in the year 1898, when addressing the Medical Society of the State of California.
 The first use of the word "onanism" to consistently and specifically refer to masturbation is a pamphlet first distributed in London in 1716, titled "Onania, or the Heinous Sin of self-Pollution, And All Its Frightful Consequences, In Both Sexes, Considered: With Spiritual and Physical Advice To Those Who Have Already Injured Themselves By This Abominable Practice." It drew on familiar themes of sin and vice, this time in particular against the "heinous sin" of "self-pollution", with dire warnings that those who so indulged would suffer:
 Disturbances of the stomach and digestion, loss of appetite or ravenous hunger, vomiting, nausea, weakening of the organs of breathing, coughing, hoarseness, paralysis, weakening of the organ of generation to the point of impotence, lack of libido, back pain, disorders of the eye and ear, total diminution of bodily powers, paleness, thinness, pimples on the face, decline of intellectual powers, loss of memory, attacks of rage, madness, idiocy, epilepsy, fever and finally suicide.
 Included were letters and testimonials supposedly from young men ill and dying from the effects of compulsive masturbation. The pamphlet then goes on to recommend as an effective remedy a "Strengthening Tincture" at 10 shillings a bottle and a "Prolific Powder" at 12 shillings a bag, available from a local shop.
"Onania" was a huge success with over 60 editions published and being translated into several languages.
 In 1743–45, the British physician Robert James published A Medicinal Dictionary, in which he described masturbation as being "productive of the most deplorable and generally incurable disorders" and stated that "there is perhaps no sin productive of so many hideous consequences".
 One of the many horrified by the descriptions of malady in Onania was the notable Swiss physician Samuel-Auguste Tissot. In 1760, he published L'Onanisme, his own comprehensive medical treatise on the purported ill-effects of masturbation. Citing case studies of young male masturbators amongst his patients in Lausanne, Switzerland as basis for his reasoning, Tissot argued that semen was an "essential oil" and "stimulus", the loss of which in great amounts would cause "a perceptible reduction of strength, of memory and even of reason; blurred vision, all the nervous disorders, all types of gout and rheumatism, weakening of the organs of generation, blood in the urine, disturbance of the appetite, headaches and a great number of other disorders."
 In a 17th-century law code for the Puritan colony of New Haven, Connecticut, blasphemers, homosexuals and masturbators were eligible for the death penalty.
 Though Tissot's ideas are now considered conjectural at best, his treatise was presented as a scholarly, scientific work in a time when experimental physiology was practically nonexistent. The authority with which the work was subsequently treated – Tissot's arguments were even acknowledged and echoed by Kant and Voltaire – arguably turned the perception of masturbation in Western medicine over the next two centuries into that of a debilitating illness.
 In 1812 Benjamin Rush included "Of the Morbid State of the Sexual Appetite" as chapter 18 of his book on diseases of the mind. In it he cites excessive eating, intemperance in drinking, and idleness as causative factors of onanism. Earlier in the book (page 33) he claims there is a "train of physical and moral evils which this solitary vice fixes upon the body and mind." In his charge of mentally ill people he notes three driven to mania by onanism (page 48). In his observation of "congenital idiotism" (page 292) he notes, "The venereal appetite exists in them with great force, and they gratify it after puberty by onanism."
 By 1838 Jean Esquirol declared in his Des Maladies Mentales that masturbation was "recognized in all countries as a cause of insanity."
 In the 1870 book A Solemn Appeal Relative to Solitary Vice, and the Abuses and Excesses of the Marriage Relation, edited by James Springer White, and written by Ellen G. White,  we find:
 If the practice [of self-indulgence] is continued from the age of fifteen and upward, nature will protest against the abuse he has suffered, and continues to suffer, and will make them pay the penalty for the transgression of his laws, especially from the ages of thirty to forty-five, by numerous pains in the system, and various diseases, such as affection of the liver and lungs, neuralgia, rheumatism, affection of the spine, diseased kidneys, and cancerous humors. Some of nature's fine machinery gives way, leaving a heavier task for the remaining to perform, which disorders nature's fine arrangement, and there is often a sudden breaking down of the constitution; and death is the result.
 Females possess less vital force than the other sex, and are deprived very much of the bracing, invigorating air, by their in-door life. The result of self-abuse in them is seen in various diseases, such as catarrh, dropsy, headache, loss of memory and sight, great weakness in the back and loins, affections of the spine, and frequently, inward decay of the head. Cancerous humor, which would lie dormant in the system their lifetime, is inflamed, and commences its eating, destructive work. The mind is often utterly ruined, and insanity supervenes.
 Doctor John Harvey Kellogg (February 26, 1852 – December 14, 1943) was an especially zealous campaigner against masturbation. Kellogg was able to draw upon many medical sources' claims such as "neither the plague, nor war, nor small-pox, nor similar diseases, have produced results so disastrous to humanity as the pernicious habit of onanism," credited to one Dr. Adam Clarke. Kellogg strongly warned against the habit in his own words, claiming of masturbation-related deaths "such a victim literally dies by his own hand," among other condemnations.  Kellogg believed the practice of "solitary-vice" caused cancer of the womb, urinary diseases, nocturnal emissions, impotence, epilepsy, insanity, and mental and physical debility – "dimness of vision" was only briefly mentioned.
In Plain Facts for Old and Young, Kellogg issued a warning on the evils of sex. Of the 644 pages, 97 address "Secret Vice (Solitary Vice or Self-Abuse)", its symptoms and results. Included are 39 signs indicating someone is masturbating. 
He recommended, to cure children from this "solitary vice", bandaging or tying their hands, covering their genitals with patented cages, sewing the foreskin shut and electrical shock, and circumcision without anesthesia, which would break the habit. In order to prevent it, he advised parents first to teach children to avoid handling their genitalia, and as they get more mature, to inform them "of the evil consequences". He also warned parents against "evil associations", servants, and "wicked or ignorant" nurses who would masturbate children in order to quiet them.
 Sigmund Freud wrote of the "disease of masturbation": "He was suffering from the effects of masturbation."
 In the 1990s, Abd al-Aziz bin Baz, the Grand Mufti of Saudi Arabia, argued masturbation causes disruption of the digestive system, inflammation of the testicles, damage to the spine, "trembling and instability in some parts of the body like the feet", weakening of the "cerebral glands" leading to decreased intellect and even "mental disorders and insanity".
 Immanuel Kant regarded masturbation as a violation of the moral law. In the Metaphysics of Morals (1797) he made the a posteriori argument that 'such an unnatural use of one's sexual attributes' strikes 'everyone upon his thinking of it' as 'a violation of one's duty to himself', and suggested that it was regarded as immoral even to give it its proper name (unlike the case of the similarly undutiful act of suicide). He went on, however, to acknowledge that 'it is not so easy to produce a rational demonstration of the inadmissibility of that unnatural use', but ultimately concluded that its immorality lay in the fact that 'a man gives up his personality ... when he uses himself merely as a means for the gratification of an animal drive'.
 The 18th-century philosopher Jean-Jacques Rousseau saw masturbation as equal to 'mental rape', and discussed it in both Émile and Confessions. He argued that it was the corrupting influence of society that led to such unnatural acts as masturbation and that humans living a simple life amidst nature would never do such things.[citation needed]
 This continued well into the Victorian Era, where such medical censure of masturbation was in line with the widespread social conservatism and opposition to open sexual behavior common at the time.
In 1879, Mark Twain wrote a speech titled Some Thoughts on the Science of Onanism which he ended with the words:
 Of all the various kinds of sexual intercourse, this has the least to recommend it. As an amusement it is too fleeting; as an occupation it is too wearing; as a public exhibition there is no money in it. It is unsuited to the drawing room, and in the most cultured society it has long since been banished from the social board…
 So, in concluding, I say: If you must gamble away your life sexually, don't play a Lone Hand too much.
 When you feel a revolutionary uprising in your system, get your Vendome Column down some other way — don't jerk it down.
 Twain, Mark (1879). Some Thoughts on the Science of Onanism (Speech). Stomach Club. Paris, France.
 There were recommendations to have boys' trousers constructed so that the genitals could not be touched through the pockets, for schoolchildren to be seated at special desks to prevent their crossing their legs in class and for girls to be forbidden from riding horses and bicycles because the sensations these activities produce were considered too similar to masturbation. Boys and young men who nevertheless continued to indulge in the practice were branded as "weak-minded." Many "remedies" were devised, including eating a bland, meatless diet. This approach was promoted by Dr. John Harvey Kellogg (inventor of corn flakes) and Rev. Sylvester Graham (inventor of Graham crackers). The medical literature of the times describes procedures for electric shock treatment, infibulation, restraining devices like chastity belts and straitjackets, cauterization or – as a last resort – wholesale surgical excision of the genitals. Routine neonatal circumcision was widely adopted in the United States and the UK at least partly because of its believed preventive effect against masturbation (see also History of male circumcision). In later decades, the more drastic of these measures were increasingly replaced with psychological techniques, such as warnings that masturbation led to blindness, hairy hands or stunted growth. Some of these persist as myths even today. Referring to such viewpoints and treatments, Messer and Walker stated: "These are some of the darkest pages of religious and medical history."
 In 1905, Sigmund Freud addressed masturbation in his Three Essays on the Theory of Sexuality and associated it with addictive substances. He described the masturbation of infants at the period when the infant is nursing, at four years of age, and at puberty.
 In 1910, the meetings of the Vienna psychoanalytic circle discussed the moral or health effects of masturbation but its publication was suppressed.
 Medical attitudes toward masturbation began to change at the beginning of the 20th century when H. Havelock Ellis, in his seminal 1897 work Studies in the Psychology of Sex, questioned Tissot's premises, cheerfully named famous men of the era who masturbated and then set out to disprove (with the work of more recent physicians) each of the claimed diseases of which masturbation was purportedly the cause. "We reach the conclusion", he wrote, "that in the case of moderate masturbation in healthy, well-born individuals, no seriously pernicious results necessarily follow."
 Robert Baden-Powell, the founder of The Scout Association, incorporated a passage in the 1914 edition of Scouting for Boys warning against the dangers of masturbation. This passage stated that the individual should run away from the temptation by performing physical activity which was supposed to tire the individual so that masturbation could not be performed. By 1930, however, Dr. F. W. W. Griffin, editor of The Scouter, had written in a book for Rover Scouts that the temptation to masturbate was "a quite natural stage of development" and, citing Ellis' work, held that "the effort to achieve complete abstinence was a very serious error."
 "Concerning Specific Forms of Masturbation" is a 1922 essay by Austrian psychiatrist and psychoanalyst Wilhelm Reich. 
In the seven and a half page essay Reich accepts the prevalent notions on the roles of unconscious fantasy and the subsequent emerging guilt feelings which he saw as originating from the act itself.
 The works of sexologist Alfred Kinsey during the 1940s and 1950s, most notably the Kinsey Reports, insisted that masturbation was an instinctive behaviour for both males and females, citing the results of Gallup Poll surveys indicating how common it was in the United States. Some critics of this theory held that his research was biased and that the Gallup Poll method was redundant for defining "natural behavior".
 In the US masturbation has not been a diagnosable condition since DSM II (1968). The American Medical Association consensually declared masturbation as normal in 1972.
 Thomas Szasz states the shift in scientific consensus as "Masturbation: the primary sexual activity of mankind. In the nineteenth century it was a disease; in the twentieth, it's a cure."
 In the 1980s Michel Foucault was arguing masturbation taboo was "rape by the parents of the sexual activity of their children": 
 To intervene in this personal, secret activity, which masturbation was, does not represent something neutral for the parents. It is not only a matter of power, or authority, or ethics; it's also a pleasure.
 In 1994, when the Surgeon General of the United States, Dr. Joycelyn Elders, mentioned as an aside that it should be mentioned in school curricula that masturbation was safe and healthy, she was forced to resign, with opponents asserting that she was promoting the teaching of how to masturbate.