Long subtraction calculator
Subtract whole numbers column by column, the way it is taught at school: 905 minus 187 gives 718 with two borrows. It handles numbers of up to 4096 digits and says how many columns needed a borrow. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Minuend
- 905
- Subtrahend
- 187
- Difference
- 718
- Borrow count
- 2
Long subtraction is the column method taught in every arithmetic course: align two whole numbers on the ones place, walk from right to left, and borrow from the next higher column whenever a digit is too small. This calculator takes the minuend and the subtrahend as decimal strings so the operands can be far larger than a native integer type, then applies that exact schoolbook walk and returns the difference as a string. Leading zeros are stripped.
What long subtraction is and how borrowing works
Long subtraction is the written algorithm that produces the difference of two non-negative whole numbers one decimal place at a time. You write the minuend above the subtrahend, lining up the ones, tens, hundreds, and every higher place. Starting at the ones column you subtract the lower digit from the upper digit.
When the upper digit is large enough the result of that column is simply their difference. When it is not, you borrow: the current upper digit increases by ten and the next higher column of the minuend is reduced by one. That borrowed ten is exactly the place-value identity that ten ones make a ten, ten tens make a hundred, and so on, so the value of the minuend never changes — only how it is written across columns.
Cascading borrows appear whenever a run of zeros sits to the left of a too-small digit, as in one thousand minus one, which becomes nine hundred ninety-nine after three successive borrows. The method is deterministic, works for any length of decimal string, and is the same procedure printed in elementary textbooks. This calculator implements that walk on digit characters rather than on a language-native integer, so a number with dozens or hundreds of digits is handled the same way a three-digit classroom example is handled.
The response reports whether any borrow occurred and how many columns needed one, which is useful when you are checking a student's work column by column instead of only comparing the final answer.
Where step-by-step subtraction is useful
Classrooms and tutoring platforms use a long subtraction calculator so learners can check a handwritten column layout without a teacher redoing every borrow by hand. Exam-prep generators and learning-management systems need a deterministic oracle that marks a too-large subtrahend as invalid rather than silently returning a negative string a buggy grader might treat as success. Accounting and inventory scripts that already store quantities as decimal strings — invoice totals, stock counts, serial tallies — can subtract without converting through a floating-point type that would round past fifteen significant digits.
Failed validation does not consume balance. Keep each operand within the published digit ceiling, pin the returned difference string in tests, and you get reproducible exact subtraction for homework, LMS plugins, and edge workers without standing up a computer-algebra system or a big-integer library of your own.
What you can do with it
Classroom and homework checks
Let students submit a minuend and a subtrahend and verify the exact difference plus whether any column borrowed, matching the paper algorithm.
Exact string arithmetic in scripts
Subtract inventory counts, invoice totals, or other decimal-string quantities that may exceed the safe integer limit without floating-point rounding.
FAQ
How do I subtract two whole numbers with this long subtraction calculator?
Send the minuend and the subtrahend as decimal digit strings.
How large can the numbers be?
Each operand may have at most 4096 decimal digits. Send values as strings so digits past the language's safe integer limit stay exact; leading zeros are stripped before the comparison and the subtraction.
What does borrowing mean in long subtraction?
When the top digit in a column is smaller than the one below it, you add ten to it and take one away from the next column to the left. The top number keeps its value; only the way it is spread across the columns changes.
Why does 905 minus 187 need two borrows?
In the ones column 5 is smaller than 7, so it borrows. The tens column has a 0 on top, which then has to borrow from the hundreds as well. The hundreds need no borrow, and the result is 718.
Can the result of a long subtraction be negative?
No. If the number you take away is larger than the one you start from, the calculator stops with a clear message instead of inventing a negative answer, because it only works with whole numbers of zero or more.
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/long-subtraction \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"minuend":"905","subtrahend":"187"}'const res = await fetch("https://api.kit.forhosting.com/math/long-subtraction", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"minuend": "905",
"subtrahend": "187"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/long-subtraction",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"minuend": "905",
"subtrahend": "187"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/long-subtraction", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"minuend":"905","subtrahend":"187"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"minuend":"905","subtrahend":"187"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/long-subtraction", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"minuend": "905",
"subtrahend": "187"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.long_subtraction",
"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_digits | 4096 |
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
If the subtrahend is larger than the minuend the request fails with invalid_input instead of inventing a negative answer, because this tool covers non-negative integers only.
Input contract, the digit walk, and error behaviour
Each field is a decimal digit string; leading zeros are allowed and then stripped so that seven and zero-zero-seven compare as the same number. After both operands are canonicalized the engine compares them by length and then lexicographically. If the subtrahend exceeds the minuend the task fails with a clear message that long subtraction of non-negative integers requires the minuend to be at least as large — the tool does not emit a leading minus or a wrapped unsigned result. When the operands are equal the difference is the single digit zero and no borrow is recorded. POST a JSON body with two required fields: minuend, the non-negative integer being subtracted from, and subtrahend, the non-negative integer being taken away. Numeric JSON integers and numeric strings are accepted for convenience, but values that must stay exact past the fifty-three-bit safe-integer limit should always be sent as strings. Missing fields, empty strings, minus signs, decimal points, thousands separators, letters, and strings longer than four thousand ninety-six digits all fail with invalid_input naming the field, and those failures are not billed. Otherwise the core pads the subtrahend with leading zeros, walks from the ones place to the highest place, applies the borrow flag, strips leading zeros from the result, and returns minuend, subtrahend, difference, borrowed, borrow_count, and equal.
Integration use cases
Exam and LMS auto-grading
Mark long-subtraction items with a deterministic oracle that rejects a larger subtrahend as invalid_input and never invents a negative result.
Technical questions
What happens if the subtrahend is larger than the minuend?
The task fails with invalid_input. This calculator covers non-negative integers only, so a larger subtrahend is rejected instead of returning a negative difference, and the failed call is not billed.
Does the calculator show whether borrowing was needed?
Yes. The response includes borrowed (true when at least one column borrowed) and borrow_count (how many columns needed a ten from the next place), so you can check a student's column work, not only the final digits.
What does the long subtraction calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.