The previous descriptions are all correct, but here's a "formula" that you asked about:

Take the amount of earned runs allowed by a pitcher and divide that by innings pitched. Keep in mind that some people write fractions of innings as decimals (for example, 6 1/3 innings is sometimes written as 6.1). Then take the number you get and multiply that by 9. This will give you a pitchers exact ERA over any period of time you desire to know.

The formula basically looks like this:

Earned Runs / Innings Pitched x 9 = ERA