Matrix calculator
Add, subtract or multiply two matrices of up to fifty rows and fifty columns: adding the 2×2 matrices 1, 2, 3, 4 and 5, 6, 7, 8 gives 6, 8, 10, 12. Shapes that cannot be combined are refused, never padded with zeros. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Operation
- Add tax
- Rows
- 2
- Cols
- 2
- Rows a
- 2
- Cols a
- 2
A matrix calculator that adds, subtracts, or multiplies two rectangular numeric matrices is a staple of linear algebra homework, exam generators, and engineering notebooks. This capability accepts two matrices as row-major arrays of rows of finite numbers, plus the chosen operation add, subtract, or multiply, and returns the resulting matrix with its dimensions and a short formula string. Addition and subtraction require identical shapes; multiplication requires the column count of the first matrix to equal the row count of the second. No network, no model tokens, and a deterministic numeric contract you can pin in tests.
What add, subtract, and multiply mean for two matrices
Linear algebra treats a matrix as a rectangular table of numbers, written in row-major order: the first inner array is the first row, the next inner array is the second row, and so on. The three elementary binary operations on two matrices are addition, subtraction, and multiplication, and each has a different compatibility rule. Addition and subtraction are entrywise: the result has the same shape as both inputs, and each entry is the sum or the difference of the corresponding entries.
That is defined only when both matrices share the same number of rows and the same number of columns; a two-by-three matrix cannot be added to a two-by-two matrix, and this calculator refuses to invent missing entries or pad with zeros. Multiplication is the linear-algebra product, not entrywise times: if A is m by n and B is n by p, the product is m by p, and entry i,j is the dot product of row i of A with column j of B.
The inner dimensions must match—columns of A equal rows of B—or the product is undefined. This matrix calculator implements exactly those three textbook definitions and nothing else: no inverse, no determinant, no transpose, and no eigenvalues.
Where a unified matrix calculator earns its keep
Classrooms and tutoring platforms use a single matrix calculator so learners can check addition, subtraction, and the product without flipping between three tools or mixing up entrywise times with the true matrix product. Exam-prep generators need a deterministic oracle that marks incompatible shapes as errors instead of silently padding, which a buggy grader might treat as a valid extra credit path. Failed validation does not consume balance.
Keep requests inside the fifty-by-fifty limit, pin the rounded result in tests, and you get reproducible matrices for homework, LMS plugins, and edge workers without standing up symbolic math infrastructure of your own.
What you can do with it
Classroom and homework checks
Let students submit two row-major matrices and an operation, then verify the sum, difference, or product against the textbook definition without mixing up shapes.
Exam and LMS auto-grading
Mark matrix arithmetic items with a deterministic oracle that rejects incompatible dimensions and never invents padding or an entrywise product when multiply was asked.
Notebooks and small linear maps
Add, subtract, or multiply classroom-sized blocks in scripts and 2D transform pipelines without importing a full linear-algebra library.
FAQ
How do I add, subtract, or multiply two matrices?
Send two rectangular row-major arrays a and b plus operation set to add, subtract, or multiply.
When are matrix dimensions incompatible?
Add and subtract require identical shapes. Multiply requires the column count of a to equal the row count of b.
Is multiply the same as multiplying entries one by one?
No. Multiply is the linear-algebra product: each output entry is a row–column dot product. Entrywise times is not offered; use add or subtract for entrywise work.
What matrix sizes are supported?
Each matrix may have at most 50 rows and 50 columns, must be rectangular and non-empty, and every entry must be a finite number.
What size is the result when I multiply two matrices?
It takes the number of rows of the first matrix and the number of columns of the second. A two-by-three matrix times a three-by-two matrix gives a two-by-two result, and each entry pairs one row of the first with one column of the second.
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/math/matrix \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":[[1,2],[3,4]],"b":[[5,6],[7,8]],"operation":"add"}'const res = await fetch("https://api.kit.forhosting.com/math/matrix", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": [
[
1,
2
],
[
3,
4
]
],
"b": [
[
5,
6
],
[
7,
8
]
],
"operation": "add"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/matrix",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": [
[
1,
2
],
[
3,
4
]
],
"b": [
[
5,
6
],
[
7,
8
]
],
"operation": "add"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/matrix", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":[[1,2],[3,4]],"b":[[5,6],[7,8]],"operation":"add"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":[[1,2],[3,4]],"b":[[5,6],[7,8]],"operation":"add"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/matrix", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a": [
[
1,
2
],
[
3,
4
]
],
"b": [
[
5,
6
],
[
7,
8
]
],
"operation": "add"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.matrix",
"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_rows | 50 |
max_cols | 50 |
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
Incompatible dimensions fail with invalid_input instead of silent padding or broadcasting.
What add, subtract, and multiply mean for two matrices
You choose the operation, send the two row-major arrays, and receive the resulting matrix or a typed invalid_input when the shapes cannot be combined for the operation you asked for.
Input contract, response shape, and error behaviour
Field a is the first matrix: a non-empty array of rows, each row a non-empty array of finite numbers, all rows the same length so the matrix is rectangular. Field b is the second matrix in the same row-major form. Example: adding [[1,2],[3,4]] and [[5,6],[7,8]] yields [[6,8],[10,12]]. Multiplying a two-by-three matrix by a three-by-two matrix yields a two-by-two product. Failed validation is not billed. POST a JSON body with three required fields. Each numeric cell may arrive as a JSON number or as a numeric string; missing fields, empty strings, non-finite values, jagged rows, and empty matrices fail with invalid_input that names the offending field. Matrices are capped at fifty rows and fifty columns so a single request stays inside a Worker isolate. On success the body returns result as the output matrix in the same row-major nested-array form, rows and cols as the result shape, operation as the canonical name actually applied, the input shapes rows_a, cols_a, rows_b, and cols_b, parsed copies of a and b, and a formula string you can display next to the answer. Pair the response with your own typesetting if you need prettyprinted brackets; this endpoint returns JSON numbers only and does not emit plots.
Where a unified matrix calculator earns its keep
Engineering and science notebooks often chain a small add and a small multiply when assembling linear maps, stiffness blocks, or 2D transforms; calling a tiny parse API avoids pulling a full computer-algebra system for a classroom-sized array. Spreadsheet macros and LMS plugins can post two row-major arrays and an operation and receive a JSON result they can write back into cells.
Technical questions
What does the matrix calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.