I don't believe they've ever released the actual formula for how it's calculated. A lot of the stats are currently skewed because there were issues with stat recording and matches counting when they shouldn't, and that's where you see a lot of discrepancies. Stardock did say they will start over with the rankings when they're satisfied that the stats are fully working, but right now they're not going back to correct the bad data as they're fixing it up.
The general principle is that you gain more exp for winning against a higher ranked opponent than a lower ranked, and you lose less for losing against a higher ranked than a lower ranked. Custom games are reported for stats, but are not part of experience calculations (I think a bunch of the bad data is still from when Custom games counted, which is why you see low game counts and weirdly high exp since now Custom games are tucked away elsewhere for viewing).