Floor division is a type of division that rounds the result down to the nearest whole number, always in the direction of negative infinity. If you divide 7 by 2, regular division gives you 3.5, but floor division gives you 3. The “floor” part means you always round down, never up, dropping whatever fractional part remains.
How Floor Division Differs From Regular Division
Standard division produces an exact (or approximate) decimal result: 7 ÷ 2 = 3.5. Floor division takes that result and rounds it down to the largest whole number that doesn’t exceed it. So 7 floor-divided by 2 equals 3, because 3 is the largest integer less than or equal to 3.5.
This is subtly different from simply chopping off the decimal (truncation). For positive numbers, the two look identical: truncating 3.7 and flooring 3.7 both give you 3. The difference shows up with negative numbers, which is where most confusion lives.
The Negative Number Surprise
Floor division always rounds toward negative infinity. That means the result moves further from zero when the quotient is negative. For example, -7 floor-divided by 2 gives you -4, not -3. The exact result is -3.5, and rounding toward negative infinity takes you to -4.
Truncation, by contrast, rounds toward zero. Truncating -3.5 gives -3. Many programming languages use truncation for their default integer division, so switching to floor division in a language like Python can catch people off guard. If you’re porting code between languages, this is the single most important behavioral difference to watch for.
The // Operator in Python
Python is the language where most people first encounter floor division, because it has a dedicated operator for it: the double slash //. This was introduced to separate two kinds of division into distinct operators. A single slash / always returns a decimal result (true division), while // always returns a floored result.
The semantics are straightforward: a // b is equivalent to applying the mathematical floor function to a / b. A few examples:
7 // 2returns3-7 // 2returns-410.5 // 2returns5.09.0 // 2returns4.0
Notice the type behavior: when both operands are integers, the result is an integer. When either operand is a float, the result is a float, but it’s still a floored value with no fractional part. So 10.5 // 2 produces 5.0, not 5. The number is the same, but the data type is a float.
Floor Division in Other Languages
Not every language has a built-in floor division operator. In JavaScript, for instance, dividing two BigInt values uses truncation (rounding toward zero), not flooring. The ECMAScript specification explicitly defines BigInt division as truncating the quotient. To get true floor division in JavaScript, you’d need to use Math.floor() on the result of a regular division.
In C and C++, integer division also truncates toward zero. There is no built-in floor division operator, so you’d use the floor() function from the math library if you need rounding toward negative infinity. Java behaves similarly, truncating by default. Python stands out by making floor division a first-class operator baked into the language’s syntax.
The Connection to the Modulo Operator
Floor division and the modulo (remainder) operator are mathematically linked. For any two integers a and b (where b isn’t zero), there’s a fundamental relationship: a = b × q + r, where q is the quotient and r is the remainder. The remainder is always between 0 and the absolute value of b.
In Python, the // operator gives you q and the % operator gives you r, and they’re always consistent with each other. This means a == (a // b) * b + (a % b) is always true. This consistency is one reason Python chose floor division over truncation. Languages that use truncating division often produce negative remainders, which can create unexpected bugs in algorithms that depend on modular arithmetic.
Practical Uses of Floor Division
Floor division comes up constantly in everyday programming, often in places you might not immediately recognize.
Pagination is a classic example. If you have 47 items and want to display 10 per page, 47 // 10 tells you there are 4 full pages (with a partial fifth page holding the remaining 7 items). Grid and tile calculations work the same way. If you’re covering a surface that’s 137 centimeters long with tiles that are 15 centimeters wide, 137 // 15 tells you 9 complete tiles fit along that length.
Time conversions rely on floor division too. Given 7,384 seconds, you can find the number of complete hours with 7384 // 3600, which gives 2. Then you use the remainder to calculate leftover minutes and seconds. Index mapping is another common pattern: converting a one-dimensional array index into row and column positions for a two-dimensional grid uses floor division for the row and modulo for the column.
Bitwise Shifting as Floor Division
At the hardware level, there’s an elegant relationship between floor division and binary arithmetic. Shifting a binary number to the right by one position is equivalent to floor-dividing by 2. Shifting right by two positions divides by 4, shifting by three divides by 8, and so on. Each shift divides by 2 raised to the number of positions shifted.
This works because binary is base 2. When you shift digits to the right, the rightmost digits “fall off,” which is exactly what flooring does: it discards the fractional part. This principle holds in any number base. Shifting digits right by k positions in base q is equivalent to floor-dividing by q^k. In practice, bitwise right shifts can be faster than division operations on some hardware, which is why low-level code sometimes uses them as an optimization when dividing by powers of 2.
Division by Zero
Floor division by zero follows the same rules as regular division by zero: it’s not allowed. In Python, 7 // 0 raises a ZeroDivisionError. In C, integer division by zero produces undefined behavior, meaning the program could crash, produce garbage, or do anything else. Some operating systems catch this and raise a signal or exception, but the language itself makes no guarantees. Floating-point division by zero typically produces infinity rather than an error, but floor division on integers offers no such safety net.

