Before a match, each player's rating implies an "expected score" — roughly, their odds of winning. A 1200 vs. a 1200 is a coin flip; a 1400 vs. a 1200 is roughly a 76% favorite. After the result, both ratings shift by the same amount in opposite directions — the winner gains exactly what the loser loses.
expected(A) = 1 / (1 + 10^((ratingB − ratingA) / 400))
delta = round(K × (1 − expected(winner)))
winner += delta
loser −= delta
Beating a stronger opponent is worth more because your expected score was lower going in — upsets pay out closer to the full K=32, while a huge favorite winning as expected only nets a couple of points.