Its a formula. The greater the rating spread, the more points you gain - so beating someone 100 points higher will more points than beating someone 100 points lower. Additionally, the higher rated you are, the more stable your rating is. A 2000 rated player will gain less points from beating a fellow 2000 than a 1000 player will beating another 1000.
How exactly calculate the points are won or lost after the games?

Depends on the K factor. The K factor for a lower rated player could be 50 points or more, while the K factor for a master and above can be as little as 10 points. Points can also go up or down for a draw depending on which player is rated higher and by how much.

A quick way to estimate is actual - expected then multiply that by 20.
Actual:
Win is 1 point
Draw is 1/2
Loss is zero.
Expected:
2/3 for stronger player rated 100 higher (1/3 for weaker)
3/4 for stronger player rated 200 higher (1/4 for weaker)
4/5 for stronger player rated 300 higher (1/5 for weaker)
Examples:
Win vs player rated 100 points higher.
Actual = 1
Expected = 1/3
Rating change = about +13
Draw against player rated 300 points lower
Actual = 1/2
Expected = 4/5
Rating change = about -6

Chess.com uses glicko though, which basically gives a multiplier for rating changes for users who are new or have been inactive.
So a new player who should have gained 13 (in my above example) may instead gain 400 points... but their next game the multiplier is lower. Lets say they win again against someone rated 100 points higher, they may only gain 244 (just using random numbers). Lets say they play a lot of games that day (maybe 20 or 30) then their multiplier will be close to 1 and they will only gain 13... maybe even a little less. Their multiplier will then stay near 1 for many days or even weeks.
Importantly, the opponent will NOT lose 400 or 244 points. The points they lose will depend on their own multiplier.
This lets players with unreliable ratings (new payers and inactive players) to get to their correct rating faster while having less of an impact on their opponents.
If you want specific math formulas you can google "glicko rating system" or look here:
http://www.glicko.net/glicko.html
How exactly calculate the points are won or lost after the games?