An even number is an integer divisible by 2 with remainder 0. In math form: n = 2 * k for some integer k.
Remember
n is even ↔ n % 2 == 0
Examples:
10 % 2 == 0 → even
11 % 2 == 1 → odd
0 % 2 == 0 → even
-4 % 2 == 0 → even
n
n % 2
Result
10
0
Even
11
1
Odd
0
0
Even
-4
0
Even
Approach
How to Check an Even Number in Python
Four clear steps — then pick modulo, bitwise, or a step-by-two range loop.
Read the integer n (positive, negative, or zero).
Compute n % 2 (or check the least significant bit with n & 1).
If the remainder is 0 (or the LSB is 0), n is even.
To list evens in a range, test each value — or start at the first even and add 2.
Method
Idea
Time
Best for
Modulo
n % 2 == 0
O(1)
Interviews, clearest logic
Bitwise
(n & 1) == 0
O(1)
Optional follow-up, LSB check
Step by 2
Start at first even, add 2
O(N/2)
Listing evens in a range
Pseudocode
Pseudocode
function IsEven(n):
return (n mod 2) == 0
function PrintEvens(start, end):
for i from start to end:
if IsEven(i):
output i
// Faster range listing:
function PrintEvensStep(start, end):
i = start
if i is odd:
i = i + 1
while i <= end:
output i
i = i + 2
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Even test
n % 2 == 0
Odd test
n % 2 != 0
Bitwise even
(n & 1) == 0
Zero
0 is even
Negatives
-4 is even; -3 is odd
Classic check
10 → even; 11 → odd
Try it
Live Preview
Enter any integer to see the remainder and the even/odd verdict.
Whole numbers only. Tap a chip or type a value.
Result
n = 10
n % 2 = 0
(n & 1) = 0
Verdict: EVEN
Trace
Worked Walkthrough — n = 10
Apply the modulo rule, then confirm with the bitwise check.
Calculation
Step 1: Compute 10 % 2
10 = 2 * 5 + 0
remainder = 0
Step 2: Remainder is 0 → even
Step 3: Bitwise check
10 in binary ends with 0
(10 & 1) = 0 → same answer
Verdict: 10 is even
Code
Python Programs
Start with the modulo helper — it is the clearest interview answer. Then reuse it for a range, and finish with the bitwise shortcut.
Example 1 — Modulo Check
Return True when the remainder by 2 is exactly zero.
python
def is_even(n: int) -> bool:
return n % 2 == 0
number = 10
if is_even(number):
print(f"{number} is an even number.")
else:
print(f"{number} is not an even number.")
Output
10 is an even number.
How It Works
is_even computes n % 2 and compares it with 0.
For 10, the remainder is 0, so the function returns True.
The caller prints the matching message based on that boolean.
Swap 10 for 11 to see the odd path.
This is the default answer to give in interviews — clear and correct.
Example 2 — Evens in a Range
Reuse the helper to print every even value from 1 to 10.
python
def is_even(n: int) -> bool:
return n % 2 == 0
start = 1
end = 10
print(f"Even numbers from {start} to {end}:")
for i in range(start, end + 1):
if is_even(i):
print(i, end=" ")
print()
Output
Even numbers from 1 to 10:
2 4 6 8 10
How It Works
range(start, end + 1) visits every integer from start to end inclusive.
Each i is tested with is_even.
Only even values are printed: 2 4 6 8 10.
Odd values like 1, 3, and 5 are skipped.
For large ranges, use range(first_even, end + 1, 2) instead of testing every integer.
Example 3 — Bitwise Check
Even integers have a least significant bit of 0, so n & 1 is 0.
python
def is_even_bitwise(n: int) -> bool:
return (n & 1) == 0
samples = [10, 11, 0, -4]
for n in samples:
label = "even" if is_even_bitwise(n) else "odd"
print(f"{n}: {label}")
Output
10: even
11: odd
0: even
-4: even
How It Works
n & 1 keeps only the least significant bit.
If that bit is 0, the number is even; if 1, it is odd.
The sample list shows positives, zero, and a negative even value.
Results match the modulo method for these integers.
Prefer modulo in interviews for readability; mention bitwise as a follow-up.
Edge Cases & Pitfalls
Check these before calling the solution done.
Zero
0 is even
0 % 2 == 0. Do not special-case zero as “neither.”
Negatives
Parity still applies
-4 is even. In Python, (-3) % 2 == 1 (nonnegative remainder).
Floats
Use integers
Even/odd is defined for integers. Do not apply % 2 to floats without a clear rule.
Range
Inclusive end
Use range(start, end + 1) when both ends should be checked. Off-by-one errors drop the last even.
Analysis
Time and Space Complexity
Program
Time
Extra space
Modulo / bitwise check
O(1)
O(1)
Scan range of size N
O(N)
O(1)
Step-by-two listing
O(N/2)
O(1)
A single parity test is constant time. Range printers grow with how many integers you visit.
Remember
Key Takeaways
Definition: divisible by 2 with remainder 0 (n = 2k).
Default test:n % 2 == 0.
Bitwise option:(n & 1) == 0.
Test set: 10 even; 11 odd; 0 even; −4 even.
One line: if n % 2 == 0, the integer is even — including zero and many negatives.
Frequently Asked Questions
An integer n is even if n = 2 * k for some integer k. Equivalently, n is divisible by 2 with remainder 0.
Use n % 2 == 0 for the clearest test. You can also use (n & 1) == 0 as a bitwise shortcut.
Yes. 0 = 2 * 0, so 0 % 2 == 0 and zero is even.
Yes. -4 is even. In Python, (-4) % 2 == 0 and (-3) % 2 == 1. The bitwise test (n & 1) == 0 also works for negatives.
Checking one number is O(1). Scanning a range of size N is O(N), or O(N/2) if you start at the first even and step by 2.