Rectangle perimeter calculator
Enter the length and width of a rectangle and get the distance around it: 10 and 5 give a perimeter of 30, twice their sum, ready for fencing, trim or baseboard. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Length
- 10
- Width
- 5
- Perimeter
- 30
The perimeter of a rectangle is the total length of its boundary: twice the sum of the length and the width. That single closed-form formula appears in every geometry course, construction estimate, fencing plan, and packaging layout that starts from two orthogonal side lengths. Zero is allowed so a flat or degenerate rectangle still has a well-defined boundary length of twice the remaining positive side.
What rectangle perimeter means and why the formula is 2(L + W)
A rectangle is a four-sided polygon with four right angles and opposite sides equal. Walking once around its outline covers the length, then the width, then the length again, then the width again, which is exactly two lengths plus two widths. Algebra folds that path into the compact identity P equals two times the sum of length and width.
Search intent clusters around phrases such as rectangle perimeter calculator, perimeter of a rectangle formula, find rectangle perimeter from length and width, and fencing calculator for a rectangular yard. Learners want a number they can check against a textbook key; contractors and hobbyists want the same number for boards, trim, baseboard, or wire.
Input contract, validation, and how the engine applies the formula
Each must be a finite number; numeric strings that parse cleanly are accepted so form posts and spreadsheet exports stay convenient. Zero is accepted on either side: the resulting figure is degenerate (a line segment of the other side doubled, then closed), yet the algebraic perimeter remains well-defined and useful for edge cases in tests. Missing fields, empty strings, Infinity, and NaN also fail before any arithmetic runs.
There is no unit conversion inside the capacity: if you send meters you get meters of perimeter; if you send inches you get inches. Keep both dimensions in the same unit system. Failed validation is not billed; only a successful item consumes the published base price.
FAQ
What formula does the rectangle perimeter calculator use?
Swapping length and width does not change the result.
What happens if length or width is negative?
Side lengths must not be negative; those validation failures are not charged.
Is the rectangle perimeter calculator free?
The browser tool runs free on your device.
Does zero length or width work?
Yes. Zero is allowed on either side. The figure is degenerate, but the algebraic perimeter 2(L + W) remains well-defined and is returned normally.
Does it matter which side I call the length?
No. Swapping the two labels leaves their sum unchanged, so the perimeter comes out the same: 10 and 5 give 30 in either order.
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/geom/rectangle-perimeter \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"length":10,"width":5}'const res = await fetch("https://api.kit.forhosting.com/geom/rectangle-perimeter", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"length": 10,
"width": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/geom/rectangle-perimeter",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"length": 10,
"width": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/geom/rectangle-perimeter", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"length":10,"width":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"length":10,"width":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/geom/rectangle-perimeter", 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": 10,
"width": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "geom.rectangle_perimeter",
"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
This rectangle perimeter calculator accepts finite non-negative length and width, rejects any negative dimension with a clear invalid_input error, and returns the perimeter as structured JSON together with the echoed dimensions and the formula string.
What rectangle perimeter means and why the formula is 2(L + W)
The formula does not depend on which side you call length and which you call width: swapping the two labels leaves the sum unchanged, so the perimeter is symmetric in its inputs. Delivering length, width, perimeter, and a short formula field as JSON makes the result easy to paste into notes, pin in automated tests, or feed into a larger materials pipeline without reimplementing the double-sum in every spreadsheet or language. Unlike area, which multiplies the sides, perimeter adds them and scales by two, so a long thin rectangle can have a large boundary while still having modest area—an intuition this endpoint makes numerical and reproducible for any consistent unit system you choose outside the engine.
Input contract, validation, and how the engine applies the formula
POST a JSON body with two required fields: length and width. Negative values fail immediately with invalid_input naming the field, because a physical or Euclidean side length cannot be less than zero. Common aliases such as l and w, or a and b, are accepted so classroom templates that already label the sides that way do not need a rewrite. The pure parse path never calls a network service, never samples randomness, and never consults the system clock, so the same pair of dimensions always yields the same JSON.
Practical uses, pricing, limits, and when to call the API
Use the free browser tool when you want an immediate rectangle perimeter while checking homework, sizing a picture frame, estimating fence or trim for a rectangular room, or verifying a packaging outline without installing computer-algebra software. Limits are intentional: only two planar dimensions, no 3D prism surface area, no irregular polygons, and no unit conversion tables. If you need a general polygon perimeter from coordinates, or a rectangular prism surface, choose those dedicated capabilities instead. Each successful request is one billable item at $0.002; invalid input does not consume balance. Pair this perimeter endpoint with a separate area calculator when you need both boundary and floor metrics—the two formulas answer different search intents and different construction questions, so keeping them as focused landings improves SEO clarity and keeps each response small.
Integration use cases
Homework and exam rectangle perimeter drills
Students and graders confirm P = 2(L + W) for arbitrary non-negative sides, including clear rejection when a dimension is negative.
Fencing, trim, and frame length estimates
Home and shop notes that list only length and width recover total boundary length as structured JSON for materials lists and simple cost sheets.
Deterministic fixtures for geometry tests
Pipelines that seed unit tests or interactive rectangle demos call a pure perimeter oracle instead of reimplementing the double-sum in every language.
Technical questions
How do I calculate the perimeter of a rectangle with this API?
Send a JSON body with finite non-negative length and width to geom.rectangle_perimeter. The response returns length, width, perimeter, and the formula P = 2 × (length + width).