In more detail
Multiply each course's grade points by its credits, add them and divide by total credits. On the common US 4.0 scale A = 4, B = 3, C = 2, D = 1 and F = 0; schools that use plus and minus grades typically add values such as 3.7 for A− and 3.3 for B+, but the exact table varies by institution. Some high schools also report a "weighted" GPA in which honors or advanced courses earn an extra half or full point, so values above 4.0 are possible.
Why it matters
Scholarships, graduate programs and employers often set GPA cut-offs, so a small error matters. The usual mistake is averaging semester GPAs directly: a semester with more credits must count for more. Pass/fail courses and withdrawn courses normally count toward credits earned but not toward the GPA.
Example
One semester: an A (4.0) in 3 credits, a B (3.0) in 4 and a C (2.0) in 3:
(4.0 × 3 + 3.0 × 4 + 2.0 × 3) / (3 + 4 + 3) = 30 / 10 = 3.00
Combining it with a later 15-credit semester at 3.5:
(3.0 × 10 + 3.5 × 15) / 25 = 82.5 / 25 = 3.30
The naive average of 3.0 and 3.5 would give 3.25.
Common confusion
GPA is a Weighted average with credits as the weights, not a plain average of grades or semesters.