How it is calculated
For one expiry, take every strike as a possible settlement price. At each one, add up what the options would pay out: calls pay the settlement minus the strike when it is higher, puts pay the strike minus the settlement when it is lower, each times its open interest. Max pain is the settlement price where that total is smallest, the price at which option holders as a whole lose the most premium.
Why price is said to drift toward it
The theory is that dealers, hedging large open interest near expiry, end up pushing price toward the strikes where most options die worthless. In crypto the main expiry is on Deribit, every Friday at 08:00 UTC, with the largest at the end of each month and quarter.
The limits
Max pain ignores which side dealers hold, how they hedge and everything that moves price besides options. The evidence for a pull is mixed: when there is one, it tends to show only in the last hours before a large expiry. It reads best next to gamma exposure: positive gamma near the max pain strike is when a pin is most plausible.