Rectangle calculator
A rectangle 5 long and 3 wide has an area of 15 and a perimeter of 16. Enter the two sides once and read both figures in your own unit, squared for the area, so carpet and baseboard come from the same measurements. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Length
- 5
- Width
- 3
- Area
- 15
- Perimeter
- 16
The rectangle calculator computes the two numbers everyone needs from a rectangle: its area and its perimeter. There is no unit conversion, no guessing, and no ambiguity: whatever unit you measure in is the unit the answers come back in, squared for the area. Both dimensions must be positive finite numbers; anything else is rejected with a clear error before any computation happens.
What area and perimeter actually tell you
Area and perimeter answer two different questions about the same shape, and mixing them up is one of the most common measurement mistakes. The area tells you how much surface the rectangle covers — how much carpet a room needs, how much paintable wall you have, how much fabric a panel consumes. It grows with the product of the two sides, so doubling both sides quadruples it.
The perimeter tells you how long the boundary is — how much baseboard, fence, trim or edging you need to go all the way around. It only adds the sides together, so doubling both sides merely doubles it. A long thin strip and a compact square can share the same area while needing wildly different amounts of border material, which is why buying supplies from area alone so often comes up short.
Getting both numbers at once, from the same two measurements, is the point of this calculator: you enter the length and width once and read off whichever figure the job actually needs, in the units you measured in.
How the computation works
The math is the schoolbook formula, applied exactly: the area is the length multiplied by the width, and the perimeter is twice the sum of the two. Both dimensions are validated before anything is computed — each must be a positive finite number, which means zero, negative values, empty input, text that is not a number, and infinities are all rejected with a descriptive error instead of producing a silent wrong answer. Numeric strings like "2.5" are accepted and converted, because real-world measurements often arrive as text.
There is no randomness, no clock, and no network call anywhere in the computation: the same two inputs always produce the same two outputs, which is what makes the result safe to cache, audit and quote in a document.
When you need both figures at once
A mobile app can offload the check so a user typing "abc" into the width field gets a clean error rather than a NaN propagated into an invoice. Batch jobs that normalize measurement spreadsheets can stream rows through it and rely on the rejection of non-positive values as a data-quality gate. Because the capability is deterministic and stateless, results are trivially cacheable and testable: your integration tests can assert exact outputs.
And because the same code runs free on this page, the person writing the specification can verify by hand exactly what the paid pipeline will compute — no drift between the documentation, the demo and production behavior.
What you can do with it
Quote flooring and fencing from room dimensions
Feed length and width per room and get the square meters of material plus the linear meters of skirting in one call per room.
FAQ
What inputs does it accept?
A length and a width, each a positive finite number.
What units does it use?
Whatever units you send. If length and width are in meters, the perimeter comes back in meters and the area in square meters.
What formulas does it apply?
Results are rounded to six decimal places for stable, reproducible output.
Does it compute the diagonal or anything else?
No. It returns exactly the area and the perimeter. For the diagonal, use the dedicated rectangle diagonal capability.
Is the result deterministic?
Yes. There is no randomness, clock or network in the computation — the same inputs always produce byte-for-byte identical outputs.
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/generic-rectangle \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"length":5,"width":3}'const res = await fetch("https://api.kit.forhosting.com/math/generic-rectangle", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"length": 5,
"width": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/generic-rectangle",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"length": 5,
"width": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/generic-rectangle", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"length":5,"width":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"length":5,"width":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/generic-rectangle", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"length": 5,
"width": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.generic_rectangle",
"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.
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
You send the length and the width — in any unit, as plain numbers — and you get both results back in one call, computed with the exact formulas area = length × width and perimeter = 2 × (length + width). It runs free in your browser on this page, and the same deterministic code answers API requests for $0.002 per call, so the result you see here is exactly the result your application will get.
How the computation works
Results are rounded to six decimal places, which is far beyond any practical measurement precision and keeps the output stable across machines and languages, so an answer computed in your browser is byte-for-byte identical to the one the API returns.
Where a rectangle API earns its place
Nobody needs an API to multiply two numbers once — the value appears when the calculation is embedded in a system that runs it a thousand times. A quoting engine that prices flooring, fencing, glass or printing by dimensions can call this endpoint per line item and get consistent, validated numbers instead of re-implementing validation in every service.
Integration use cases
Validate dimensions in a quoting pipeline
Reject zero, negative or non-numeric measurements at the edge with a clear invalid_input error instead of letting a NaN reach an invoice.
Normalize measurement spreadsheets in bulk
Stream rows of length/width pairs through the API and use the deterministic output as an auditable, cacheable result.
Technical questions
What does it cost?
$0.002 per request via the API. It is also free to run in your browser on this page, with the exact same code.