Weighted average calculator
Combine numbers that do not count equally: for a grade where the midterm and the final are worth 40% each and homework 20%, enter weights of 0.4, 0.4 and 0.2. You get the weighted average, the weighted sum and the total weight. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Values
- 80, 90, 70
- Weights
- 0.2, 0.5, 0.3
- N
- 3
- Weighted mean
- 82
- Weighted sum
- 82
- Total weight
- 1
A weighted average (weighted mean) multiplies each observation by a weight that reflects its importance, credit hours, frequency, or confidence, then divides the sum of those products by the sum of the weights. Unlike a plain arithmetic mean that treats every row as equal, this formula lets midterms count more than quizzes, portfolio holdings pull by market value, or survey strata contribute by population size.
What a weighted mean is and when equal averaging is the wrong tool
Start from the plain arithmetic mean: add every value and divide by how many values you have. That formula assumes each observation deserves the same vote. In real data that assumption often fails.
A course grade that is forty percent midterm, forty percent final, and twenty percent homework is not the average of three percentage scores; it is a weighted mean of those three scores with weights 0.4, 0.4, and 0.2. A portfolio return that averages holding returns without market-value weights understates large positions and overstates tiny ones. A regional survey that averages city means without population weights treats a village the same as a metro area.
When every weight equals one, the formula collapses back to the ordinary mean, so equal weighting is a special case rather than a rival definition. When weights are frequencies, the same formula is the mean of a frequency table without expanding every repeated row. Because the divisor is the sum of weights and not the count of rows, two lists with the same values but different weight profiles produce different answers—and that difference is the entire point of the tool.
Empty lists never produce a mean; a total weight of exactly zero never produces a quotient. Both fail validation immediately so callers can distinguish bad input from a legitimate zero result that only appears when values themselves are zero under a non-zero weight total.
What you can do with it
Course grades and credit-weighted scores
Teachers and students combine component scores with syllabus weights (midterm, final, homework) into one official grade without hand-spreadsheet errors.
Portfolio and allocation averages
Analysts weight holding returns or risk metrics by market value or target allocation so large positions dominate the blended figure correctly.
Survey strata and frequency tables
Researchers and pipelines turn group means plus population or frequency weights into a single population-level weighted mean for reports and tests.
FAQ
What formula does the weighted mean use?
When every weight is one, this equals the ordinary arithmetic mean of the values.
What happens if the weights sum to zero?
A zero total weight would require division by zero, so the calculator rejects it instead of returning NaN or Infinity.
Must values and weights have the same length?
Empty lists and non-finite entries are also rejected. Validation failures are not charged.
Is the weighted average calculator free?
The browser tool runs free on your device.
Do the weights have to add up to 1?
No. The result is divided by the sum of the weights, whatever it is, so weights of 40, 40 and 20 give the same answer as 0.4, 0.4 and 0.2. Only a total weight of exactly zero is rejected.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/stat/weighted-mean \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"values":[80,90,70],"weights":[0.2,0.5,0.3]}'const res = await fetch("https://api.kit.forhosting.com/stat/weighted-mean", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"values": [
80,
90,
70
],
"weights": [
0.2,
0.5,
0.3
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/weighted-mean",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"values": [
80,
90,
70
],
"weights": [
0.2,
0.5,
0.3
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/weighted-mean", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"values":[80,90,70],"weights":[0.2,0.5,0.3]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"values":[80,90,70],"weights":[0.2,0.5,0.3]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/weighted-mean", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"values": [
80,
90,
70
],
"weights": [
0.2,
0.5,
0.3
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.weighted_mean",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_values | 100000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
This calculator takes two equal-length arrays of finite numbers—values and weights—returns the weighted mean, the weighted sum, the total weight, and the pair count, and rejects empty lists, length mismatches, non-finite entries, and a total weight of zero with a clear invalid_input error so pipelines never invent a silent NaN. The arithmetic is fully deterministic, runs free in your browser, and is available over the API at $0.002 per successful request with no language model and no external statistics service on the hot path.
What a weighted mean is and when equal averaging is the wrong tool
The weighted mean fixes this by pairing each value x_i with a weight w_i, forming the product x_i times w_i, summing those products into a weighted sum, summing the weights into a total weight W, and dividing: weighted mean equals weighted sum over W.
How this calculator validates pairs and computes the weighted mean
Call the capability with two required array fields: values (the observations) and weights (their importance). After validation the core walks both lists once, coercing each entry to a finite number, accumulating the sum of value times weight and the sum of weights. The engine also accepts aliases numbers, data, x, and scores for values, and w, freqs, and importance for weights, so scripts that already speak in those terms do not need a rename step. Validation rejects a missing field, a non-array, an empty array, lists longer than the published maximum, any entry that is not a finite number, and a length mismatch between the two lists, all with invalid_input and without charging balance. If the total weight is exactly zero, the request fails with invalid_input because division by zero is undefined; negative individual weights are allowed mathematically and only the zero sum is forbidden. The response returns n, weighted_mean, weighted_sum, total_weight, and the coerced values and weights arrays so downstream code can recompute or audit the intermediate quantities without re-sending the request.
Practical use, limits, pricing, and delivery
Use the browser tool when you want an immediate weighted average while checking a grade formula, blending returns by allocation, or explaining why equal averages mislead stratified data without installing a statistics package. Results are fully deterministic: the same values and weights always yield the same weighted mean, weighted sum, and total weight. There is no language model, no external statistics service, and no randomness, so the capability is safe to pin in continuous-integration checks and reproducible lesson materials. Each successful request is one billable item at $0.002; failed validation does not consume balance. Accepted lists stay bounded for Worker isolates: up to one hundred thousand pairs cover classroom tables, portfolio sleeves, and typical analytics excerpts while still finishing quickly. Wire the endpoint into gradebook helpers, finance tutorials, survey post-processing, coding-interview sandboxes, or preprocessing steps where you already prefer a closed-form weighted mean over approximate streaming sketches or opaque black-box calculators that hide whether they normalize weights, drop zeros, or silently skip missing pairs when they print a single average field.
Technical questions
How do I compute a weighted average with this calculator?
Send JSON with values and weights (two equal-length arrays of numbers) to stat.weighted_mean. The response returns weighted_mean, weighted_sum, total_weight, n, and the coerced arrays.