How to calculate average share price?

Can someone explain the formula and process for calculating the average price of shares when buying at different price levels?