How Our Math Calculators Work

This page explains the formulas, input rules, and rounding behind our average, mean, median, mode, weighted average, LCM, GCF, standard deviation, and age calculators, and lists the test cases every release must pass.

Last updated November 6, 2026

Definitions

We follow the NIST/SEMATECH e-Handbook of Statistical Methods, sections 1.3.5.1 Measures of Location and 1.3.5.6 Measures of Scale.

MeasureHow we calculate it
Mean (average)Sum of the values ÷ number of values
MedianMiddle value of the sorted list; with an even count, the average of the two middle values
ModeEvery value that appears most often. If all values appear once, there is no mode
RangeLargest value − smallest value
Sample standard deviation√(Σ(x − mean)² ÷ (N − 1)); not shown for a single value
Population standard deviation√(Σ(x − mean)² ÷ N)
Weighted averageΣ(value × weight) ÷ Σ(weight)

LCM and GCF

Methods follow OpenStax Prealgebra 2e, 2.5 (least common multiple) and OpenStax Elementary Algebra 2e, 7.1 (greatest common factor).

ResultHow we calculate it
GCFEuclid's algorithm: divide the larger number by the smaller, then the smaller by the remainder, until the remainder is 0; the last nonzero remainder is the GCF. For 3 or more numbers, GCF(a, b, c) = GCF(GCF(a, b), c)
LCMLCM(a, b) = a ÷ GCF(a, b) × b, chained for 3 or more numbers, in exact integer (BigInt) arithmetic so large results aren't rounded
Prime factorizationTrial division up to the square root; the GCF takes the lowest power of each shared prime and the LCM the highest power of every prime
ListingFactors are listed when every number is 10,000 or less; multiples when the LCM is at most 50 times the smallest number

Inputs: 2 to 20 whole numbers from 1 to 1,000,000,000,000. Negative numbers are replaced by their positive values; 0, decimals, and other text aren't accepted.

Factors

The factor calculator uses the definitions in OpenStax Prealgebra 2e, 2.4 and NIST DLMF 27.2:

Inputs: whole numbers from 1 to 1,000,000,000,000; negatives use their positive value; 0 and decimals aren't accepted. Lists longer than 240 numbers are shortened, with the full list in a collapsed block; factor pairs aren't listed past 240 pairs. The division ladder divides by the smallest prime factor until 1 is left. Test cases: 24 has 8 factors (2³ × 3), sum 60, abundant; 36 has 9, with the pair 6 × 6; 6, 28 and 496 are perfect; 360 has 24 factors; 720,720 has 240; 1,000,000,000,000 = 2¹² × 5¹² has 169; the common factors of 24 and 36 are 1, 2, 3, 4, 6 and 12.

Volume and Cubic Yards

The volume calculator and cubic yard calculator share one engine:

Displayed values keep up to 3 decimals (2 from 1,000 up, 4 significant digits below 1, scientific notation from 1015). These two calculators accept thousands commas (1,000), a leading $ and a trailing %, and reject comma decimals such as 1,5 with a hint to use a period; values above 1,000,000,000 aren't accepted. Not modelled: material weight (tons), compaction, and supplier minimums. Test cases: 10 × 10 × 10 ft = 1,000 ft³ = 37.037 yd³ = 7,480.52 gal; a 10 cm cube = 1 L; 10 × 10 ft at 3 in = 25 ft³ = 0.9259 yd³; 324 sq ft at 1 in = 1 yd³; 12 × 12 ft at 3 in with 10% extra = 1.467 yd³, 20 bags of 2 cu ft, $58.67 at $40 per yd³.

Slope and Lines

The slope calculator has three modes.

Pythagorean Theorem

The Pythagorean theorem calculator uses a² + b² = c² for a right triangle with legs a, b and hypotenuse c (OpenStax Prealgebra 2e, 9.3): c = √(a² + b²) and a = √(c² − b²), with the hypotenuse required to be the longest side. With three sides it compares the two smaller squares with the largest exactly; equal means a right triangle by the converse of the theorem (Common Core 8.G.B.6); the two shorter sides must add to more than the longest. Inputs are read as exact fractions (BigInt arithmetic), so missing sides are simplified radicals (√74, 3√3, 10√2) with a decimal; fractional bases are bracketed in the steps, as (5/2)². Squares too large to hold exactly fall back to a decimal answer. In check mode the longest side is treated as the hypotenuse, and near-misses within 0.1% get a rounding note. Extras: angle A = arctan(a ÷ b), B = 90° − A, area = ½ab, perimeter, height to the hypotenuse = ab ÷ c.

Test cases: 3, 4 → 5; 5, 12 → 13; 5, 7 → √74 ≈ 8.6023; 1, 1 → √2; 10, 10 → 10√2; c 13 with a 5 → 12; c 6 with a 3 → 3√3; 5, 12, 13 is right, 6, 7, 9 isn't (85 ≠ 81); 3-4-5 has angles 36.87° and 53.13°, area 6, height 2.4.

Square, Cube and Nth Roots

The square root calculator gives the principal root: √m is the non-negative number whose square is m (OpenStax Elementary Algebra 2e, 9.1). It simplifies by pulling the largest perfect n-th power out of the radicand, using ⁿ√(ab) = ⁿ√a·ⁿ√b (9.2; Intermediate Algebra 2e, 8.2); a fraction p/q uses ⁿ√(p·qⁿ⁻¹) ÷ q. Odd roots of negative numbers are negative real numbers; even roots of negative numbers have no real value (OpenStax Intermediate Algebra 2e, 8.1). Prime factors come from trial division. Inputs up to 1,000,000,000,000; roots 2 to 10. A fraction is a perfect power when its reduced numerator and denominator both are; radicands above 1012 are shown as decimals. Arithmetic is exact (BigInt).

Test cases: √144 = 12; √50 = 5√2 ≈ 7.071068; √72 = 6√2; √0.25 = 1/2; √(9/16) = 3/4; ∛54 = 3∛2; ∛(−8) = −2; ∜32 = 2∜2; the 5th root of 64 = 2 × ⁵√2; √−16 has no real root.

Quadratic Formula

The quadratic formula calculator solves ax² + bx + c = 0 with a ≠ 0 as x = (−b ± √(b² − 4ac)) ÷ 2a, and classifies the discriminant: zero gives one double rational solution, a positive rational square (numerator and denominator both perfect squares, tested exactly at any size) two rational solutions, other positive values two irrational solutions, negative values two complex solutions with i = √−1 (2.4) (OpenStax College Algebra 2e, 2.5). a, b and c are read as exact fractions; roots are written (P ± Q√r) ÷ L in lowest terms when the radicand is small enough to simplify (up to 1012), with i for complex roots, plus decimals; otherwise decimals only. A bare x factor is written first, and factored forms with root denominators over 1,000 are left out. With rational roots r₁ = p₁/q₁ and r₂ = p₂/q₂ the factored form is (a ÷ q₁q₂)(q₁x − p₁)(q₂x − p₂). Vertex h = −b ÷ 2a, k = f(h); axis x = h; opens up if a > 0; y-intercept c (5.1). Coefficients up to ±1,000,000.

Test cases: x² − 5x + 6 → 2, 3, (x − 2)(x − 3), vertex (5/2, −1/4); 2x² + x − 3 → −3/2, 1, (2x + 3)(x − 1); x² − 6x + 9 → 3 (double), (x − 3)²; x² + 0.12345x → −0.12345 and 0 (rational); −2x² + 8x − 6 → −2(x − 1)(x − 3); x² − 2x − 2 → 1 ± √3; x² + 3x − 1 → (−3 ± √13)/2; x² + 2x + 5 → −1 ± 2i; 2x² + 3x + 4 → (−3 ± i√23)/4; a = 0 is rejected.

Rounding

The rounding calculator works on the number as exact decimal digits (BigInt, up to 30 digits), never as a binary float, so 1.005 to two places is 1.01. School method: look at the digit to the right of the place; 5 or more adds 1 to the place digit, otherwise it stays; digits to the right are dropped or zeroed (OpenStax Prealgebra 2e, 1.1 and 5.1), applied by this calculator to the size of a negative number (−2.5 → −3, half away from zero; OpenStax covers positive numbers only). Half to even: when the dropped digits are exactly 5 followed by zeros, the kept digit stays if even and goes up if odd (NIST SP 811, B.7.1); OpenStax Chemistry 2e uses the same tie rule for significant figures. Ceiling rounds toward +∞, floor toward −∞, truncate toward zero. Significant figures: nonzero digits, captive zeros and trailing zeros after a decimal point count, leading zeros never do, and trailing zeros in a whole number are treated as not significant (OpenStax Chemistry 2e, 1.5); rounding to n figures keeps n digits from the first nonzero one, re-sizing if rounding carries (9.99 to 2 figures is 10), with scientific notation when trailing zeros would be ambiguous.

Test cases: 843 → 840 (nearest ten); 3.14159 → 3.14; 2.675 → 2.68; 1.005 → 1.01; 9.96 → 10.0; −2.5 → −3 (school), −2 (half to even); 6.9749505 → 6.974950 and 6.9749515 → 6.974952 (half to even, 7 digits, 6 decimal places); 0.004567 → 0.00457 (3 figures); 123,456 → 123,000 = 1.23 × 10⁵; 0.00450 has 3 significant figures.

Decimals and Fractions

The decimal to fraction calculator writes the digits after the point over the place value of the last digit and simplifies by the greatest common factor (OpenStax Prealgebra 2e, 5.1), all in BigInt (up to 18 digits). Repeating decimals are entered with the repeating block in parentheses, or by marking the last 1 to 6 digits as repeating (parentheses win if both are given): with n digits before the block and k in it, x = (all digits − the digits before the block) ÷ (10ⁿ × (10ᵏ − 1)); a decimal that eventually repeats is rational (Common Core 8.NS.A.1). Fraction to decimal divides the top by the bottom (5.3), tracking remainders to find where the digits repeat (shown in parentheses and with a bar). The nearest fraction in halves to 64ths is round(x × D) ÷ D, simplified, shown whenever the exact fraction isn't already on that scale, with how far under or over it is. A trailing "…" is noted and the digits typed are converted exactly.

Test cases: 0.75 = 3/4; 0.625 = 5/8; 4.09 = 4 9/100; 2.125 = 2 1/8; 0.(3) = 1/3; 0.1(6) = 1/6; 0.(142857) = 1/7; 0.(9) = 1; 1.2(34) = 611/495; 3/8 = 0.375; 5/6 = 0.8(3); 2.71 ≈ 2 11/16 (16ths).

Remainder

The remainder calculator divides whole numbers (0 and up, up to 30 digits) in BigInt: quotient = floor(dividend ÷ divisor), remainder = dividend − quotient × divisor, checked as quotient × divisor + remainder = dividend; dividing by zero is undefined (OpenStax Prealgebra 2e, 1.5). Long division steps are shown for dividends up to 12 digits. The mixed number is quotient plus remainder/divisor in lowest terms; the decimal comes from long division with repeating digits detected. Negative numbers aren't accepted, since remainder conventions for them differ.

Test cases: 1,439 ÷ 4 = 359 R 3 (359 3/4, 359.75); 17 ÷ 5 = 3 R 2 (3.4); 10 ÷ 3 = 3 R 1 (3.(3)); 100 ÷ 8 = 12 R 4 (12 1/2); 123456789012345678901234567890 ÷ 7 leaves 0.

Scale Factor

The scale factor calculator uses k = new length ÷ original length and new = original × k, with exact fractions; similar figures have corresponding sides in the same ratio (OpenStax Prealgebra 2e, 9.3). k is shown as a fraction, a new:original ratio (k = a/b → a:b) and a percent; area changes by k² and volume by k³, since they multiply two and three lengths. Scale drawings (Common Core 7.G.A.1): at drawing:real = 1:N, real = drawing × N in the same unit, then converted with 1 in = 2.54 cm, 12 in = 1 ft, 36 in = 1 yd, 63,360 in = 1 mi.

Test cases: 4 → 10 = 5/2 (area 25/4, volume 125/8); 12 → 3 = 1/4 (1:4); 6 × 3/2 = 9; 3 in at 1:48 = 144 in = 12 ft; 5 m at 1:100 = 5 cm on paper; 2 in at 1:87 = 14.5 ft.

Percent Yield

The percent yield calculator uses percent yield = actual yield ÷ theoretical yield × 100% (OpenStax Chemistry 2e, 4.4), solved for whichever value is left blank: actual = theoretical × percent ÷ 100, theoretical = actual ÷ (percent ÷ 100). If all three are given, the percent is recalculated. The shortfall is theoretical − actual. An actual yield or percent of 0 is allowed (theoretical yield must be above 0). Results above 100% get a note. Example 4.13's theoretical yield: 1.274 g ÷ 159.62 g/mol × 1 × 63.55 g/mol = 0.5072 g Cu.

Test cases: 0.392 g of 0.5072 g = 77.29% (OpenStax Example 4.13, 77.3%); 15 of 20 = 75%; theoretical 50 at 80% = 40; actual 40 at 80% = 50.

Area of a Shape

The area calculator finds the area of one shape from lengths in the chosen unit (mm, cm, m, km, in, ft, yd or mi), then converts it.

Square Footage and Area

The square footage calculator adds and subtracts areas:

Test cases: 12 × 12 ft = 144 sq ft = 16 sq yd = 13.378 m²; 12' 6" × 10' 3" = 128.125 sq ft; 20 × 12 + 10 × 8 − 3 × 4 = 308 sq ft; a circle 10 ft across = 78.54 sq ft; 144 sq ft with 10% extra, 20 sq ft boxes and $3.50 per sq ft = 8 boxes and $554.40.

Standard Deviation and Variance

Variance

The variance calculator uses the sample variance s² = Σ(x − x̄)² ÷ (n − 1) (NIST/SEMATECH e-Handbook 1.3.5.6) and the population variance σ² = Σ(x − μ)² ÷ N (OpenStax Introductory Statistics 2e, 2.7), with the same parsing, rounding and deviations table as the standard deviation calculator above. It needs at least 2 values; the step table shows the first 200 rows.

Test cases: 2, 4, 4, 4, 5, 5, 7, 9 → sum of squares 32, sample variance 32/7 = 4.5714, population variance 4; 1, 2, 3, 4, 10 → population SD 3.1623.

Mean Absolute Deviation

The mean absolute deviation calculator uses MAD = Σ|x − x̄| ÷ n, the measure of variability in Common Core 6.SP.B.5c, which NIST calls the average absolute deviation (NIST 1.3.5.6). It also shows NIST's median absolute deviation, median(|x − median|). One value is enough; when every value is the same both are 0.

Test cases: 2, 4, 4, 4, 5, 5, 7, 9 → mean absolute deviation 12 ÷ 8 = 1.5, median absolute deviation 0.5; 1, 2, 3, 4, 10 → 2.4.

Z-Score and the Normal Curve

The z-score calculator uses z = (x − μ) ÷ σ and x = μ + zσ (OpenStax Introductory Statistics 2e, 6.1). The percentile is the area to the left of z under the standard normal curve, P(X < x) (6.2). That area, Φ(z), is computed with Hart's double-precision rational approximation (as published by Graeme West, 2005), checked against reference values such as Φ(1.96) = 0.9750021; the area to the right is 1 − Φ(z), and the area between −|z| and |z| is Φ(|z|) − Φ(−|z|). For a percentile, z is found by bisection on Φ to about 10⁻¹² and snapped to 0 at the 50th percentile. σ must be above 0; a percentile must be strictly between 0 and 100. Areas below 0.0001 are shown in scientific notation, and percents below 0.0001% as "< 0.0001%".

Test cases: x = 17, μ = 5, σ = 6 → z = 2, area to the left 0.9772 (97.72%); z = 1, 2, 3 → areas between 68.27%, 95.45%, 99.73% (empirical rule 68–95–99.7); 90th percentile with μ = 63, σ = 5 → z = 1.2816, x = 69.4078 (OpenStax 69.4); z = 1.96 → 97.5% to the left.

Probability

The probability calculator uses, from OpenStax Introductory Statistics 2e, 3.1: P(A) = outcomes in A ÷ total equally likely outcomes, P(not A) = 1 − P(A), P(A | B) = P(A and B) ÷ P(B); and from 3.3: P(A and B) = P(A) × P(B) for independent events, P(A and B) = 0 for mutually exclusive events, P(A or B) = P(A) + P(B) − P(A and B). Neither = 1 − P(A or B); exactly one = P(A or B) − P(A and B). Repeated tries: at least once = 1 − (1 − p)ⁿ and every time = pⁿ, from the complement (3.1) and the multiplication rule for independent events (3.3); exactly k = C(n, k)·pᵏ·(1 − p)ⁿ⁻ᵏ (4.3), computed with logarithms, with "at most" and "at least" as sums; mean np, standard deviation √(np(1 − p)).

Exponents

The exponent calculator uses bⁿ = b used as a factor n times (OpenStax Elementary Algebra 2e, 6.2); b⁰ = 1 for b ≠ 0 (6.5); b⁻ⁿ = 1/bⁿ (6.7); b^(m/n) = (ⁿ√b)ᵐ, with no real value for an even root of a negative number (Intermediate Algebra 2e, 8.3); bˣ = y ⇔ x = log_b y = log y ÷ log b (College Algebra 2e, 6.3, 6.5).

Scientific Notation

The scientific notation calculator writes a number as a × 10ⁿ with 1 ≤ |a| < 10 and n an integer, converts by moving the decimal point, multiplies by multiplying the numbers and adding exponents, and divides by dividing and subtracting (OpenStax Elementary Algebra 2e, 6.7). Addition and subtraction align both numbers to the same power of 10 (OpenStax Chemistry 2e, Appendix B). E notation follows Excel's Scientific format, aE±n = a × 10ⁿ (Microsoft Support).

Percentiles and Quartiles

The percentile calculator sorts the data and finds the value at the kth percentile three ways:

Matrices

The matrix calculator and the matrix multiplication calculator share one engine. It does exact arithmetic on fractions (BigInt numerators and denominators), so results never pick up rounding error. Decimals are shown only alongside, rounded to 4 decimal places (very small values to 4 significant figures).

GCF and LCM Worksheets

The GCF and LCM worksheets are generated, not typed by hand. A seeded random generator (mulberry32) picks the numbers, so every set can be rebuilt exactly from its set number: the PDFs, the on-page generator and shared links all show the same problems.

Tips

The tip calculator works in whole cents. The tip is the base times the percentage, rounded half up to the cent; the base is the bill before tax, or the bill plus tax if you choose. The total is the bill plus tax plus tip.

Age

Percentages

Input Rules

How Results Are Rounded for Display

Calculations use full double-precision arithmetic. Results are trimmed to 12 significant digits to remove binary rounding noise (so 0.1 + 0.2 shows as 0.3), then displayed with up to 4 decimals, or up to 10 with "More decimals" on the average and mean, median, mode calculators. The weighted average calculator shows up to 4 decimals.

Test Cases

Every change to the calculation engine must pass these cases before release. They run automatically with Node's built-in test runner against the same engine file the calculators load in your browser.

#InputExpected
185, 90, 78, 92, 88Mean 86.6, median 88, no mode, range 14, sum 433
22, 4, 4, 4, 5, 5, 7, 9Mean 5, median 4.5, mode 4 (3 times), population SD 2, sample SD 2.1381
31, 1, 2, 2, 3Modes 1 and 2
40.1, 0.2Mean 0.15, sum 0.3
5"1,234 5,6"; "12,345.5, $7, 80%"; "10 $1,200, $3"1234, 5, 6; 12345.5, 7, 80; 10, 1200, 3
6Weighted: 92 × 20, 85 × 30, 78 × 5082.9 (simple average 85)
7Weighted: 10 × 100, 12 × 5010.6667
8300,000; 320,000; 350,000; 360,000; 2,000,000Mean 666,000, median 350,000
9Weighted: 4.8 × 20, 4.2 × 300, 4.5 × 804.29 (simple average 4.5)
10"100,250,300"One value, 100250300, flagged as read with thousands commas
11LCM/GCF: 12, 18 · 8, 12 · 6, 10GCF 6, 4, 2; LCM 36, 24, 30
12LCM/GCF: 15, 20 · 15, 18 (OpenStax Examples 2.52, 2.53)LCM 60, 90; GCF 5, 3
13LCM/GCF: 24, 36, 60 · 9, 28GCF 12, LCM 360; GCF 1 (relatively prime), LCM 252
14Euclid: 1,071, 4621,071 = 2 × 462 + 147; 462 = 3 × 147 + 21; 147 = 7 × 21 + 0 → GCF 21, LCM 23,562
15360; 1,000,000,000,000 and 999,999,999,9892³ × 3² × 5; GCF 1, LCM 999,999,999,989,000,000,000,000 (exact)
16Age: born 1/1/1962, on 12/31/2026 (SSA POMS GN 00302.400 example)Social Security age 65; ordinary age 64 (65 on 1/1/2027)
17Age: born 2/29/2004, on 2/28/2022 and 3/1/2022 (§ 1-303(b))17, then 18 on March 1; 18 on February 28 with the February 28 option
18Age: born 5/20/1990, on 11/4/2026; born 1/31/2026, on 2/28/2026 and 3/31/202636 years, 5 months, 15 days; 1 month 0 days; 2 months 0 days
19Age: born 1/1/2000, on 11/4/20269,804 days (1,400 weeks and 4 days), born on a Saturday, next birthday Friday 1/1/2027 in 58 days
20Age difference: 3/10/1988 and 7/25/19913 years, 4 months, 15 days
21Age: born 11/4/1990, on 11/4/2026; born and checked on 11/4/2026; year 001936, birthday today, next birthday 11/4/2027 in 365 days; age 0, not a birthday; rejected (outside 1900–2100)
22Standard deviation: the 20 ages of OpenStax Example 2.32 (9 to 11.5)Mean 10.525, sum of squares 9.7375, sample variance 0.5125, s = 0.7159 (0.72), population variance 0.486875
23Standard deviation: 2, 4, 4, 4, 5, 5, 7, 9; one value, 5Sum of squares 32, σ = 2, s² = 4.5714; one value: σ = 0, no sample SD
24z-score of 9 in 2, 4, 4, 4, 5, 5, 7, 9; z-score of 0.1 in 0.1, 0.1, 0.12 (population SD), 1.8708 (sample SD); 0.1, 0.1, 0.1 has standard deviation exactly 0 and no z-score
2535% of 90 (OpenStax Example 6.14); 125% of 28 (same section); 9 is what % of 36 (6.18); 36 is 75% of what (6.16); 6.5% of what is 1.1731.5; 35; 25%; 48; 18
26Percent change $26 → $36 (OpenStax Example 6.23); $3.71 → $3.64 (6.24); from 038.46% increase (38.5%); 1.89% decrease (1.9%); rejected
27Percent off: $140 at 35% (OpenStax Example 6.30); $31 → $13.95 (6.31); $100 at 20% then 10%$49 off, $91; $17.05 off, 55%; $72, 28% off in total
28Percent error: 48.7 vs. expected 50; 9.457 vs. 9.807 (OpenStax Contemporary Mathematics 6.1, Exercises 24–25, answers worked from the formula)2.6%; 3.5689%
29Percent difference: 10 and 12; 12 and 10; 40 and 5018.18%; 18.18%; 22.22%

Known Limits

Update Log

Found an error? Tell us through our contact page. Corrections are listed here with the date.