Pagination offset and limit calculator
Turn a one-based page number into the exact values needed by an offset-based query.
Run — free
Provide the requested page, the number of records allowed on each page, and the total number of available items. The calculator returns the zero-based offset, the query limit, and the total page count. It also rejects page numbers or page sizes below one, helping prevent invalid database requests and inconsistent navigation controls before they reach application code.
Convert a page request into query parameters
User interfaces usually describe pagination with human-friendly page numbers, while databases and APIs often expect a zero-based offset plus a limit. This calculator connects those two conventions. Enter a page number beginning at one, a page size, and the total number of items in the full collection. The offset is calculated as the page number minus one, multiplied by the page size. The limit is the page size itself. For example, the third page of a collection displayed twenty-five items at a time starts after the first fifty items, so its offset is fifty and its limit is twenty-five. These values can be passed directly to a typical SQL LIMIT and OFFSET clause or mapped to equivalent request parameters in another service. The result is deterministic and does not inspect or fetch the underlying records. It only performs the arithmetic needed to prepare a paginated request, making it useful in backends, scripts, tests, documentation, and debugging sessions.
Understand total pages and boundary behavior
The total page count is the total item count divided by the page size and rounded upward. Rounding upward matters because a partially filled final page is still a page. If one hundred and one items are displayed twenty-five at a time, four pages hold one hundred items and a fifth page holds the remaining item. When the total item count is zero, the total page count is zero because there is no result page to display. The requested page is not clamped to that total. A request for page ten can therefore produce a valid offset even when the collection contains only three pages. That behavior is intentional: the calculator reports pagination arithmetic and leaves application policy to the caller. Your application can compare the requested page with total_pages and then return an empty result, redirect to the last page, or show a not-found response. Keeping calculation separate from policy makes the output predictable across database, REST, and user-interface workflows.
Validate inputs before building a query
Page and page_size must be safe integers greater than or equal to one. A zero or negative value would break the one-based page convention or create a meaningless limit, so either condition produces an invalid-input error. total_items must be a safe integer greater than or equal to zero because a collection cannot contain a negative or fractional number of records. Safe-integer checks also prevent silent precision loss in JavaScript when very large values are multiplied. If the computed offset exceeds the safe integer range, the request is rejected instead of returning an inaccurate number. These rules are useful beyond this calculator: applying the same validation at an API boundary prevents malformed query parameters from reaching a database adapter. The capability performs no network requests, stores no data, and uses no random or time-dependent values. The same input always produces the same output. For API automation, each request costs $0.002; the browser experience can be used to check examples while designing or troubleshooting pagination logic.
What you can do with it
Build a database query
Convert a page selected in an interface into LIMIT and OFFSET values for a SQL query.
Render pagination controls
Calculate the total page count needed to enable, disable, or label navigation controls.
Test API boundary cases
Generate expected pagination values for empty collections, partial final pages, and pages beyond the result set.
FAQ
Is the page number zero-based or one-based?
It is one-based: page 1 has offset 0, and page 2 starts after one full page_size.
How is total_pages calculated?
The calculator divides total_items by page_size and rounds upward so a partially filled final page is counted.
What happens when total_items is zero?
total_pages is 0, while offset and limit are still calculated from the requested page and page size.
Can I request a page beyond total_pages?
Yes. The calculator returns the mathematical offset and lets your application decide whether to show an empty result or reject the page.
What does an API request cost?
Each API request costs $0.002. The calculation is also available in the browser.
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/dev/pagination-offset-calc \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"page":3,"page_size":25,"total_items":123}'const res = await fetch("https://api.kit.forhosting.com/dev/pagination-offset-calc", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"page": 3,
"page_size": 25,
"total_items": 123
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/pagination-offset-calc",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"page": 3,
"page_size": 25,
"total_items": 123
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/pagination-offset-calc", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"page":3,"page_size":25,"total_items":123}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"page":3,"page_size":25,"total_items":123}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/pagination-offset-calc", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"page": 3,
"page_size": 25,
"total_items": 123
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev.pagination_offset_calc",
"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. |