Canadian Tax Brackets always seem to confuse some people, myself included until I was taught how they actually work.
This script solves the tedious task of calculating that.
So... how do Canadian Tax Brackets Work?
Canada uses a progressive tax system with separate federal and provincial/territorial tax brackets. What this means for the individual is basically only the portion of income that falls into a higher tax bracket is taxed at the higher rate, not the entire income. You can read more here.
For the year of 2025 on your federal taxes any income up to $57,375 is taxed at 14.5%. However let's say that you made $60,000 in 2025. The extra $2,625 that was over the threshold will get taxed at the next bracket of 20.5%.
The math would look something like this to calculate your federal taxes
($57,375 * 0.145) + (($60,000 - $57,375) * 0.205) = $8,857.50
You would have to do this again to get what you will pay for provincial taxes. Not my favourite pass-time if I'm being honest.
That's why I've created a script.
How to use the system
All you need to do is open a terminal window in the folder with the two python files in it and run on of the command below.
In the example I set it to 50000 but this can be any number
Windows:
py main.py 50000
MacOS/ Linux:
python3 main.py 50000
Once run it will display
Gross Pay: $50,000.00
Federal Tax: $7,250.00
Alberta Tax: $4,000.00
Total Deductions: $11,250.00
Net Pay: $38,750.00
It's really just that simple.
How does it work?
Essentially what it does is it will take the argument that you send it, in my example 50000, and pass that through a function to be calculated
I've created two lists of objects that I just called "TaxBrackets"
Essentially the tax bracket holds two values
TaxBracket:
percentage # represented in decimal form threshold # represented as a whole number to signify the dollar amount
We then make a list of those brackets that hold the percentage and the thresholds and call it something like "FederalBrackets"
The main logic comes into play with a single function that does the heavy lifting.
Conceptually it processes the tax brackets recursively. The function takes an income value, a list of the tax brackets and a counter that tracks which bracket we are currently evaluating. If the counter reaches the last bracket, the function concludes that the income has reached the top bracket and calculates the amount before passing it back up the chain. It looks something like this.
function CalculateTax(income, brackets, counter = 0):
if counter is the last index in brackets:
return income * percentage of the previous bracket
if income is greater than the threshold of the current bracket:
tax in this bracket = threshold * percentage for this bracket
remaining income = income - threshold
return tax this bracket + CalculateTax(remaining income, brackets, counter + 1) # Calls function again
if income is less than or equal to the threshold:
return income * percentage for this bracketalberta tax = CalculateTax(gross income, alberta tax brackets) federal tax = CalculateTax(gross income, federal tax brackets)