CalculateMax
HomeCategoriesPopularAboutContact
Math & Geometry
Modulus Calculator
Calculate remainders with different conventions
Convention Comparison
TruncatedJS/C/Java

Rounds quotient toward zero. Sign follows dividend.

-17 % 5 = -2

FlooredPython/Ruby

Rounds quotient toward -infinity. Sign follows divisor.

-17 % 5 = 3

EuclideanMathematical

Result is always non-negative (0 to |n|-1).

-17 mod 5 = 3

Common Examples
a mod nTruncFloorEuclid
17 % 5222
-17 % 5-233
17 % -52-32
-17 % -5-2-23
Modulus Formula

a mod n = a - n × floor(a/n)

The modulus operation finds the remainder after division. The result depends on how the quotient is rounded.

a = dividend (number being divided)

n = divisor (number dividing by)

r = remainder (result)

What is Modulus?

The modulus operation (also called modulo or mod) finds the remainder when one integer is divided by another. For example, 17 mod 5 equals 2 because 17 = 5 × 3 + 2. The modulus is fundamental in computer science, cryptography, and number theory. It is used extensively in hash functions, circular buffers, clock arithmetic, and determining if numbers are even or odd.

While the concept seems simple for positive numbers, handling negative numbers requires choosing a convention. Different programming languages use different conventions, which can lead to unexpected results when working across languages. Understanding these differences is crucial for writing portable code and debugging cross-platform applications.

Understanding Modulus Conventions

Truncated Division (JavaScript, C, Java): The quotient is rounded toward zero, and the remainder has the same sign as the dividend. This is the most common convention in low-level programming languages.

Floored Division (Python, Ruby): The quotient is rounded toward negative infinity, and the remainder has the same sign as the divisor. This convention is often preferred in mathematical applications because it provides more predictable behavior with negative numbers.

Euclidean Modulus: The remainder is always non-negative, ranging from 0 to |n|-1. This is the traditional mathematical definition and is particularly useful in number theory and cryptographic applications where negative remainders would be problematic.

Disclaimer

Modulus calculations follow standard arithmetic rules. Results may vary based on the handling of negative numbers and selected conventions. Always verify which convention your programming language uses when working with negative numbers, and consider using the Euclidean modulus for mathematical applications requiring non-negative results.

CalculateMax

Your comprehensive collection of free online calculators. Fast, accurate, and easy to use.

Categories

  • Health & Fitness
  • Finance
  • Math & Geometry
  • Physics & Engineering
  • Chemistry
  • Construction
  • Time & Date
  • Lifestyle & Daily Use
  • Business
  • Education & Learning

More Categories

  • Sports & Athletics
  • Real Estate
  • Ecommerce
  • Investment
  • Forex

Quick Links

  • Home
  • All Categories
  • Popular Calculators
  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Cookie Policy

© 2026 CalculateMax. All rights reserved. Free calculators for everyone.