{
  "id": "remainder",
  "version": "522bc95c9fbe",
  "status": "published",
  "name": "Remainder Calculator",
  "question": "What is the remainder when I divide?",
  "summary": "Divides one whole number by another and gives the whole-number quotient and the remainder, a = b × q + r with 0 ≤ r < b, exactly at any size.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/remainder-calculator",
  "markdown": "https://www.acalculator.org/math/remainder-calculator.md",
  "kind": "function",
  "method": "The division algorithm: for a whole number a and a whole number b ≥ 1 there is exactly one pair q, r with a = b × q + r and 0 ≤ r < b. q = ⌊a ÷ b⌋ and r = a − b × q.",
  "assumptions": [
    "Both numbers are whole numbers. The divisor is 1 or more; the dividend may be negative or zero.",
    "The remainder is never negative, even for a negative dividend: −17 ÷ 5 is −4 remainder 3, because 5 × (−4) + 3 = −17.",
    "The quotient, the remainder and the exact quotient are exact at any size; the exact quotient shows 12 decimal places, then … when more digits follow."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "Dividend",
        "description": "The whole number being divided (a). It may be negative.",
        "type": "string",
        "pattern": "^-?\\d+$"
      },
      "b": {
        "title": "Divisor",
        "description": "The whole number to divide by (b), 1 or more.",
        "type": "string",
        "pattern": "^-?\\d+$"
      }
    }
  },
  "outputs": {
    "remainder": {
      "label": "Remainder",
      "description": "What is left after taking away as many whole divisors as fit: r, from 0 up to b − 1.",
      "format": "integer"
    },
    "quotient": {
      "label": "Quotient",
      "description": "How many whole times the divisor fits: q, rounded down (toward minus infinity).",
      "format": "integer"
    },
    "check": {
      "label": "Check",
      "description": "The division written back as a multiplication: a = b × q + r.",
      "format": "text"
    },
    "decimal": {
      "label": "Exact quotient",
      "description": "The dividend divided by the divisor as an exact decimal, a ÷ b = q + r ÷ b, to 12 decimal places; … means more digits follow.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": 17,
      "b": 5
    },
    "outputs": {
      "remainder": "2",
      "quotient": "3",
      "check": "17 = 5 × 3 + 2",
      "decimal": "3.4"
    },
    "text": "17 ÷ 5 = 3 remainder 2."
  },
  "examples": [
    {
      "given": {
        "a": 17,
        "b": 5
      },
      "expect": {
        "quotient": 3,
        "remainder": 2,
        "decimal": "3.4",
        "check": "17 = 5 × 3 + 2"
      },
      "source": "hand calculation in content.mdx: 5 × 3 = 15, 17 − 15 = 2"
    },
    {
      "given": {
        "a": 100,
        "b": 7
      },
      "expect": {
        "quotient": 14,
        "remainder": 2,
        "decimal": "14.285714285714…"
      },
      "source": "hand calculation in content.mdx: 7 × 14 = 98, 100 − 98 = 2"
    },
    {
      "given": {
        "a": -17,
        "b": 5
      },
      "expect": {
        "quotient": -4,
        "remainder": 3,
        "decimal": "-3.4",
        "check": "−17 = 5 × (−4) + 3"
      },
      "source": "Sundstrom, Mathematical Reasoning: Writing and Proof, section 3.5 (the division algorithm): −17 = 5(−4) + 3"
    },
    {
      "given": {
        "a": 12,
        "b": 4
      },
      "expect": {
        "quotient": 3,
        "remainder": 0
      },
      "source": "hand calculation in content.mdx: 4 × 3 = 12 exactly, so the remainder is 0"
    },
    {
      "given": {
        "a": 3,
        "b": 8
      },
      "expect": {
        "quotient": 0,
        "remainder": 3,
        "decimal": "0.375"
      },
      "source": "hand calculation in content.mdx: 8 does not fit into 3, so q = 0 and r = 3"
    },
    {
      "given": {
        "a": "18446744073709551616",
        "b": 7
      },
      "expect": {
        "quotient": "2635249153387078802",
        "remainder": 2
      },
      "source": "hand calculation in content.mdx: 2⁶⁴ = 7 × 2,635,249,153,387,078,802 + 2; Python 3: divmod(2**64, 7)"
    }
  ],
  "sources": [
    "Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b; −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence",
    "Donald E. Knuth, The Art of Computer Programming, Vol. 1, §1.2.4 (x mod y = x − y⌊x ÷ y⌋)."
  ],
  "related": [
    "mod",
    "division",
    "scientific-notation"
  ],
  "changelog": [
    {
      "date": "2026-09-28",
      "note": "The exact quotient is exact at any size, by long division, to 12 decimal places."
    }
  ]
}
