The ladders use Elo (possibly Bayeselo) to rate players. There isn't a # of points you get each game- rather, your wins against better opponents (i.e., those with higher ratings) "give" you more points than wins against worse opponents. The calculation isn't too complicated but it is a lot more complex than just 40 points for win + some stuff on top. In fact, someone with a 25-25 win record might have a radically higher rating than someone with a 35-15 record.
If it's Bayeselo, your opponents' future performance also affects your rating, so that's why you might see it look like it's increasing after a loss.