Insanity is repeating the same mistakes and expecting different results.
From the book Narcotics Anonymous, which is referred to within the Narcotics Anonymous fellowship as "the basic text". The quotation was not in the "grey book" version of the basic text distributed for editing by the fellowship at large in 1980, but was in the approval version released in November, 1981. A pdf scan of the 1981 approval version can be found here, with the quote appearing on p. 11 (p. 25 of the pdf), at the end of the fourth paragraph (which begins "We have a disease; progressive, incurable and fatal").
It might have originated in some other part of the addiction recovery community, since it seems to have been in oral use prior to 1981, being cited in a 1980 text from Alcoholics Anonymous (though the link on google books is to a 1992 revised edition, so confirmation is needed that it appeared in the original 1980 version):
“When I came into the program, I heard that insanity is doing the same thing over and over and expecting different results,”
Variant: "Insanity is doing the same thing over and over again but expecting different results." Rita Mae Brown, Sudden Death (Bantam Books, New York, 1983, p. 68).
Note: This quote and variants including "The definition of insanity ..." or "One definition of ..." have been attributed to Albert Einstein, Ben Franklin, Confucius, and an old Chinese proverb, but this is its first known appearance in print.