Onanistic nomenclature aside, stimming's a repetitive movement (flapping one's hands, rocking back and forth or side to side, pacing, playing with a toy) that provides regulated sensory input. Hence the "stimulation" part of the name.
It can serve a number of purposes. Impact-bearing stims like pacing, jumping or running provide vestibular feedback which can provide a temporary improvement in proprioception. Gentler stims like rocking or flicking your fingers can help you cope with sensory overload or strong emotions, and prevent a meltdown.
They're also a form of self-expression and communication. I don't speak sign language (although learning it is on my bucket list) but my hands can tell you a lot about my state of mind:
Confused. Slow, circular motions like this mean I'm confused, thinking, or a bit bewildered. I do it a lot in shops when I'm looking for something, or while I'm figuring out how an unfamiliar machine or piece of software works. I also do it when I go into a room and then forget what I went there for.
Stop It! This one means I'm getting overwhelmed, usually by noise, and need whatever it is to just stop already. My hands are flat, palms in (like I'm going to cover my ears) and then flicked rapidly up and down. They're not usually out of synch like they are in this photo. I usually do this stim higher up, with my hands to the sides of my head, but I did it lower for the sake of this demonstration because I wanted to crop my face out of these photos - I kept pulling silly-looking 'concentrating' expressions, and the internet can do without those.
Happy! I'm pleased to see you, or excited about something. My fingers are curled lightly and my hands bounce up and down. The movement in this stim comes from my elbow, unlike the Stop It! motion which comes from the wrists.
Having talked you through all that, unless you're likely to meet me in person you might as well forget it - while there are some common stims, everyone (it's not just people on the spectrum who stim) stims differently, and the same stim might mean different things coming from different people.