GCF calculator
The greatest common factor of 48 and 18 is 6: it is the largest number on both lists of divisors. Enter two integers, signed or with a zero, and get the exact answer for reducing fractions, packing equal boxes or choosing floor tiles. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- A
- 48
- B
- 18
- Gcf
- 6
The greatest common factor of two integers is the largest whole number that divides both of them exactly, and it shows up constantly: reducing fractions, splitting quantities into equal groups, sizing tiles for a floor, simplifying ratios in code. This capability computes it with the Euclidean algorithm, the same method mathematicians have used for over two thousand years, and returns a single integer. Send two integers — positive, negative or zero, as numbers or as exact numeric strings — and get back their greatest common factor.
What the greatest common factor actually is
Take two integers, say 48 and 18. The numbers that divide 48 exactly are 1, 2, 3, 4, 6, 8, 12, 16, 24 and 48; the divisors of 18 are 1, 2, 3, 6, 9 and 18. The divisors they share are 1, 2, 3 and 6, and the greatest of those — 6 — is the greatest common factor, written gcf(48, 18) = 6.
Listing divisors works for small numbers, but it scales terribly: factoring a fifteen-digit integer is genuinely hard. The greatest common factor calculator avoids factoring entirely. It uses the Euclidean algorithm, which rests on one observation: any common divisor of a and b also divides their remainder when the larger is divided by the smaller.
Replacing the larger number by that remainder shrinks the problem at every step while preserving every common divisor, until one of the numbers reaches zero and the other is the answer. The whole computation takes at most a few dozen steps even for the largest integers JavaScript can represent exactly, and the result is always exact — no floating point, no approximation.
Inputs, signs, zero and errors
Signs do not matter: gcf(-48, 18) equals gcf(48, 18), because a divisor of a number also divides its opposite, so the algorithm works on the absolute values. Zero is a legitimate input with a precise meaning — gcf(17, 0) is 17, since every integer divides zero and the greatest divisor of 17 is 17 itself — but both fields being zero is rejected, because every integer divides zero and there is no greatest one.
Absolute values are bounded by 9007199254740991, the largest integer JavaScript represents exactly; anything larger could not be handled exactly and is refused.
Where it fits and what it costs
You meet the greatest common factor more often than the name suggests. Reducing a fraction to lowest terms is dividing numerator and denominator by their GCF. Splitting a shipment into identical boxes with nothing left over, choosing the largest square tile that covers a rectangular floor without cutting, and simplifying an aspect ratio in a responsive layout are the same question wearing different clothes.
In code it appears inside schedulers, hash functions and cryptographic routines. This capability is deliberately minimal: it returns the factor itself, nothing else, so it composes cleanly with anything that consumes it. If you need the full division steps of the Euclidean algorithm, the Bézout coefficients, or the least common multiple as well, sibling capabilities cover those.
What you can do with it
Reduce a fraction to lowest terms
Divide numerator and denominator by their greatest common factor to simplify 48/18 to 8/3 in one call.
Split quantities into equal groups
Find the largest identical batch size that divides two stock quantities exactly, with nothing left over.
Simplify ratios in a layout engine
Collapse pixel dimensions like 1920x1080 to the 16:9 ratio they represent before storing or displaying them.
FAQ
Do the signs of the numbers matter?
No. The greatest common factor is computed on the absolute values, so gcf(-48, 18) and gcf(48, 18) are both 6.
Can one of the numbers be zero?
Yes: gcf(a, 0) is |a|. Both being zero is rejected, because gcf(0,0) is undefined.
How large can the integers be?
Up to 9007199254740991 in absolute value, the largest integer that can be represented exactly. Larger values are refused rather than computed approximately.
How do I find the GCF by listing divisors?
Write down every divisor of each number and pick the largest one they share. For 48 and 18 the common divisors are 1, 2, 3 and 6, so the GCF is 6. For big numbers this gets slow, which is why the calculator uses Euclid's method instead.
How does the GCF help when tiling a floor?
The largest square tile that covers a rectangular floor without any cutting has a side equal to the GCF of the two floor lengths. The same idea splits a shipment into identical boxes with nothing left over.
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/gcf \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":48,"b":18}'const res = await fetch("https://api.kit.forhosting.com/math/gcf", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 48,
"b": 18
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/gcf",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 48,
"b": 18
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/gcf", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":48,"b":18}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":48,"b":18}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/gcf", 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": 48,
"b": 18
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.gcf",
"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_abs | 9007199254740991 |
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
Non-integer input is rejected with a clear error, and the same code that answers the API runs free in your browser on this page.
Inputs, signs, zero and errors
The endpoint takes two required fields, a and b. Each must be an integer: a JSON number like 1071 or a numeric string like "-252" that represents an exact integer — strings are convenient when the value comes from a form or a text file. Decimals such as 2.5, fractions, booleans and non-numeric text are rejected with an invalid_input error that names the offending field, because the greatest common factor is only defined for integers.
Where it fits and what it costs
The price is $0.002 per request with no per-unit surcharge, and identical requests always produce identical answers. It runs on our global edge with nothing stored after the response, and the very same module powers the free calculator on this page, so you can verify any result by hand before you wire it into a pipeline.
Technical questions
What does it cost?
$0.002 per request, with no per-unit surcharge. It is also free to run in your browser on this page.
What inputs are accepted?
Two integers, a and b, as JSON numbers or as numeric strings that are exact integers. Anything else is rejected with an invalid_input error.
Is anything stored after the call?
No. The two integers are processed and discarded; only the greatest common factor is returned.