The easy part and the two hard parts
Score divided by total, times 100. That is the arithmetic, and it is not why anyone needs a page. The two things that actually cause trouble are partial credit and unequal question weights.
Partial credit means your score is not a whole number. Half marks on two questions of a 40-question test give you 34.5 out of 40 — 86.25%, which rounds to 86% and stays a B. Enter the decimal; do not round before dividing, because rounding twice is how a boundary gets crossed by accident.
Unequal weights break the model entirely. If a test has 20 questions but the last one is worth 10 points and the rest are worth 1, then "how many did I get wrong" tells you nothing on its own. Work in points, not in questions, whenever the questions are not equal.
Worked examples
34 out of 40. 34 ÷ 40 = 0.85 → 85%, a B on a standard scale. Six questions wrong. One more correct answer would have been 87.5% and a B+; one fewer would have been 82.5% and a B−. Each question on a 40-mark test is worth 2.5 percentage points, which is a useful thing to know before an appeal about a single disputed mark.
34.5 out of 40 with partial credit. 34.5 ÷ 40 = 0.8625 → 86.25%. Still a B, but only just: 87% is a B+ at most schools, so half a mark on one more question would have moved the letter. This is the situation where rounding convention decides a grade.
Rounding, and why we tell you what we do
We round half-up to one decimal place: 86.25% displays as 86.3%, and 89.5% displays as 89.5% and is not promoted to an A−. Different tools do different things here without saying so, which is why the same score produces different letters on different sites.
Whether your instructor rounds is a separate question and one no calculator can answer. Some round 89.5 to an A−, some do not, and almost none write it down. If your grade lands within half a point of a boundary, the calculator has done all it can and the rest is a conversation.
The formula
percentage = score ÷ total × 100
The letter grade uses the standard bands, which are set out with their grade points on the letter grade to GPA page. We do not repeat the table here; your school's bands may differ from the common convention and that page explains why.
Where this stops being reliable
Curved tests need the grade curve calculator — a curve changes the relationship between raw score and grade in a way this page cannot see. Bonus questions can push a score above 100%, which is legitimate and which we display rather than capping. Rubric-scored work marked out of 12 or 17 works fine here, but the letter-grade conversion is less meaningful when the total is small: on a test out of 12, each question is worth 8.3 percentage points and there is no such thing as a B+.