how many people did Stalin really kill? what were they really killed for?
Provably? None. You don't call a judge that might've (or might've not) wrongly convicted someone a murderer, do you?
In Stalin's case, he wasn't even a judge: the only semi-serious accusations of "murder" are the permissions - jointly signed by several people; Stalin wasn't even always among the signatories - for NKVD to investigate some people (accused of terrorist activities - literally "against terrorist organizations and acts of terrorism") under special conditions, which bypassed parts of Soviet legal system.
I.e. legal actions undertaken in accordance with the Soviet equivalent of Patriot's Act (except much more limited in scope).
In 1934-1953 (since the introduction of procedure after Kirov's murder) 44.5 thousand people got investigated this way, but not all were accused of execution-worthy crime, not all were found guilty, and not all were executed (exact numbers unknown; especially, exact numbers of wrongly convicted).
how many people got purged but not killed?
The word "purging" refers to the Soviet practice of manager (or any post of note) being evaluated and then being dismissed (from the post; no prison sentence/execution implied) - if found lacking - by his subordinates. The whole process was generally conducted for the whole management and often under Party oversight, as a countermeasure against disinformation, blackmail or threats by counter-revolutionary elements - Game of Thrones has nothing on early USSR.
That said, I assume you are talking about people being sent to prison. Moreover, being sent to prison for political (counter-revolutionary) crimes. Unfortunately, Soviets had a very broad definition of counter-revolutionary (58th article). Any organized crime is automatically counter-revolutionary. Money counterfeiting? Counter-revolutionary. Desertion? Counter-revolutionary. Armed uprising?
Well, you get the idea.
Total number of imprisoned in 1921-1953 for counter-revolutionary activities is 2.369.220 (according to 1954 MVD report).
how many of them were later rehabilitated, and why?
Lots. Many. There were at least 4 significant waves of rehabilitation:
1) Beria's rehabilitations (primarily 1939-1941) - actual re-investigation to release wrongly accused - targeted those who are alive at the time.
2) Khrushchev's rehabilitation (1954-1961) - initially, an attempt to "restore historical justice" and rehabilitate everyone wrongly accused (including already dead), but quickly got subverted by the actual perpetrators of the 1937/38 into "Let's blame Stalin for everything" campaign with suppression of evidence. Primary focus was on rehabilitation of military and on people who were part of the 1937/38, but got caught abusing their rights (i.e. purging personal rivals) and were arrested by Beria and subsequently executed. Actual opponents of orthodox ML ideology - initial targets of 1937/38 (Kamenev, Zinoviev, Rykov, Bukharin, etc.) - were not rehabilitated and were considered justly convicted for their "anti-Soviet activity" (Central Committee decision of 1956).
3) Gorbachev's rehabilitation (1986-1991) - predictably, no longer concentrated on shifting blame, but on discrediting orthodox ML to justify Perestroika (and increase of Gorbachev's personal power). Thus, everyone - except Trotsky, since he wasn't ML - was considered "innocent". Especially Bukharin, whose ideas Gorbachev was using for Perestroika.
4) Post-Soviet rehabilitation (1991) - everyone gets rehabilitated. Even if you were caught pillaging and murdering by Bolsheviks in 1918, you'll probably get rehabilitation for being victim on unjust regime - because revolutionary tribunals were illegal. As one might've guessed, the idea is to discredit the whole of USSR (and Socialist ideas in general).