Batting Average Calculator

Enter a batter’s at-bats, hits, extra-base hits and walks to get the batting average, on-base percentage (OBP), slugging percentage (SLG) and on-base plus slugging (OPS). Switch to pitching for the earned run average (ERA). The formulas are the ones in Major League Baseball’s (MLB) Official Baseball Rules, so 150 hits in 500 at-bats is a .300 average.

Batting average
.300

150 hits in 500 at-bats is a .300 batting average.

On-base (OBP) .377
Slugging (SLG) .500
OPS .877

How to calculate batting average

MLB’s Rule 9.21 says: divide the hits by the at-bats. Walks, hit by pitch, sacrifices and times reaching on interference don’t count as at-bats, so they don’t change the average. Averages are written to 3 decimals, usually without the leading zero (.300).

batting average = hits ÷ at-bats

Here it is with your numbers:

  1. Batting average: 150 ÷ 500 = .300.
  2. Total bases: 95 singles + 2 × 30 + 3 × 5 + 4 × 20 = 250.
  3. Slugging: 250 ÷ 500 = .500.
  4. Times on base: 150 hits + 60 walks + 5 hit by pitch = 215.
  5. Plate appearances that count: 500 + 60 + 5 + 5 sacrifice flies = 570.
  6. On-base: 215 ÷ 570 = .377.
  7. OPS: on-base + slugging, from the exact fractions, = .877.

It means the batter got a hit in 30% of official at-bats.

Source MLB · Official Baseball Rules, 2026 edition (Rules 9.02 and 9.21) ↗

On-base percentage, slugging and OPS

  • On-base percentage (OBP) = (hits + walks + hit by pitch) ÷ (at-bats + walks + hit by pitch + sacrifice flies). Reaching on an error or a fielder’s choice doesn’t count.
  • Slugging percentage (SLG) = total bases ÷ at-bats, where a single is 1 base, a double 2, a triple 3 and a home run 4.
  • OPS = on-base percentage + slugging percentage. We add the exact fractions, then round, so OPS can differ by .001 from adding the two rounded figures.

Source MLB.com Glossary · On-base Plus Slugging (OPS) ↗MLB.com Glossary · On-base Percentage (OBP) ↗

How to calculate ERA (earned run average)

Rule 9.21(e): multiply the earned runs by 9 and divide by the innings pitched, including part innings. Each out is a third of an inning (Rule 9.02(c)), so box scores write 6⅔ innings as 6.2. The rulebook’s own example: 3 earned runs in 9⅓ innings is an ERA of 2.89.

ERA = earned runs × 9 ÷ innings pitched

Here it is with your numbers:

  1. Innings: 180.1 means 180 innings and 1 out, each out a third of an inning, so 180 1/3 innings (541 outs).
  2. Runs × 9: 60 × 9 = 540.
  3. ERA: 540 ÷ 180 1/3, or 1,620 ÷ 541 outs, = 2.99 (exact 2.9945, to 2 decimals).

It means the pitcher gave up 2.99 earned runs for every 9 innings pitched.

Sources

Related calculators