ForHosting KIT · Developer Utilities

Pagination offset and limit calculator

Convert the page a visitor picks into the values a database query expects: page 3 at 25 items per page starts at offset 50, and 123 items fill 5 pages. Pages count from one, offsets from zero. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Page
3
Page size
25
Total items
123
You get
Offset
50
Limit
25
Total pages
5

Turn a one-based page number into the exact values needed by an offset-based query. 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.

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.

How do I calculate the offset for a given page?

Subtract one from the page number and multiply by the page size. The third page at 25 items per page skips the first 50 records, so its offset is 50 and its limit is 25.

How is the total number of pages worked out?

The total item count is divided by the page size and rounded up, because a partly filled last page is still a page. With 123 items at 25 per page you get 5 pages, and an empty collection gives 0.

What happens if someone asks for a page past the last one?

You still get a valid offset, because the requested page is not cut back to the total. Page 10 of a three-page list is calculated normally, and your own application decides whether to show nothing or jump to the last page.

Why do pages start at one but the offset at zero?

People count pages from one, while a database counts how many records to skip, starting from zero. The first page therefore has offset 0, and a page number or page size below one is refused.

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.

POSThttps://api.kit.forhosting.com/dev/pagination-offset-calc

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.

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}'
{
  "page": 3,
  "page_size": 25,
  "total_items": 123
}
{
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Understand total pages and boundary behavior

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

Safe-integer checks also prevent silent precision loss in JavaScript when very large values are multiplied. 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. 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. 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. For API automation, each request costs $0.002; the browser experience can be used to check examples while designing or troubleshooting pagination logic.

Test API boundary cases

Generate expected pagination values for empty collections, partial final pages, and pages beyond the result set.

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.

Read the full KIT documentation →