Floor division is division that rounds the result down to the nearest whole number. If you divide 7 by 2, normal division gives you 3.5, but floor division gives you 3. It drops the remainder and always rounds toward negative infinity, which matters when you’re working with negative numbers.
How Floor Division Works
The core idea is simple: divide two numbers, then apply the “floor function” to the result. The floor function takes any number and rounds it down to the largest integer that’s less than or equal to it. So floor division can be expressed as: a // b = floor(a / b).
Some quick examples make this concrete:
- 7 // 2 = 3 (regular division gives 3.5, floor rounds down to 3)
- 10 // 3 = 3 (regular division gives 3.33, floor rounds down to 3)
- 9 // 3 = 3 (no rounding needed since 9 divides evenly)
When both numbers are positive, floor division behaves exactly like you’d expect: it just chops off the decimal part. The tricky part comes with negative numbers.
Why Negative Numbers Are the Tricky Part
Floor division always rounds toward negative infinity, not toward zero. This distinction doesn’t matter with positive numbers, but it changes everything with negatives.
Take -7 // 2. Regular division gives -3.5. If you rounded toward zero, you’d get -3. But floor division rounds down toward negative infinity, so the answer is -4. That catches a lot of people off guard the first time they see it. Here’s the comparison:
- -7 // 2 = -4 (floor rounds -3.5 down to -4, away from zero)
- 7 // -2 = -4 (same result, -3.5 floors to -4)
- -7 // -2 = 3 (regular division gives 3.5, floors to 3)
Some programming languages use “integer division” that truncates toward zero instead. In C++ and Java, the / operator on integers gives you -3 for -7 / 2, not -4. This is a common source of bugs when developers switch between languages.
The // Operator in Python
Python uses the double slash (//) as its floor division operator. It works on both integers and floats, and it always follows the floor(a/b) rule. When both inputs are integers, the result is an integer. When either input is a float, the result is a float with .0 at the end.
- 7 // 2 returns 3 (int)
- 7.0 // 2 returns 3.0 (float)
- 3.5 // 2.0 returns 1.0 (float)
Python’s single slash (/) always returns a float (so 7 / 2 gives 3.5), while the double slash always floors the result. This distinction was formalized in Python 3. In Python 2, single slash on two integers performed floor division by default, which caused enough confusion that the language was changed.
Floor Division in Other Languages
Most languages don’t have a dedicated floor division operator the way Python does, but they all offer a way to achieve the same result.
In Java, you’d use Math.floor() combined with regular division: (int) Math.floor((double) a / b). In C++, you include the cmath library and call floor() in the same way. JavaScript works similarly with Math.floor(a / b). The key thing to remember is that the built-in integer division in C++, Java, and JavaScript truncates toward zero rather than rounding toward negative infinity, so using the / operator alone on integers won’t give you true floor division when negative numbers are involved.
The Relationship Between Floor Division and Modulo
Floor division and the modulo operator (%) are two sides of the same coin. They’re connected by a fundamental identity: for any two numbers a and b (where b isn’t zero), a = b × (a // b) + (a % b). The floor division gives you the quotient, and modulo gives you the remainder, and together they reconstruct the original number.
For example, 17 divided by 5: the floor division gives 3 (the quotient), and 17 % 5 gives 2 (the remainder). Check: 5 × 3 + 2 = 17. This relationship holds even with negative numbers. With -17 // 5, the quotient is -4 (because floor division rounds down), and -17 % 5 is 3. Check: 5 × (-4) + 3 = -17.
This identity is why floor division’s rounding direction matters. Python chose to round toward negative infinity specifically to keep the modulo result consistent: in Python, a % b always has the same sign as b. Languages that truncate toward zero instead give a modulo result with the same sign as a. Neither is wrong, but they lead to different behavior in edge cases.
Common Uses in Programming
Floor division shows up constantly in everyday coding problems. Converting units of time is a classic example: if you have 3,672 seconds and want to know how many full minutes that is, 3672 // 60 gives you 61. Pair that with 3672 % 60 to get the 12 remaining seconds.
Pagination is another common use. If you have 47 items and display 10 per page, 47 // 10 tells you there are 4 full pages (with a partial fifth page you’d calculate separately). Index calculations in algorithms like binary search rely on floor division to find midpoints: for an array with indices 0 through 9, (0 + 9) // 2 gives you index 4.
Any time you need to split things into even whole-number groups, distribute items across containers, or convert between units where you only care about complete units, floor division is the right tool.

