Running payroll sounds like simple multiplication. Hours times rate equals gross pay. Subtract taxes. Done. Then you encounter overtime on multiple rates bonus tax withholding supplemental wages mid-year salary changes and multi-state employees.
The basic calculation
function grossPay(hourlyRate, regularHours, overtimeHours) {
return (hourlyRate * regularHours) + (hourlyRate * 1.5 * overtimeHours);
}
function netPay(gross, federalTax, stateTax, socialSecurity, medicare, deductions) {
return gross - federalTax - stateTax - socialSecurity - medicare - deductions;
}
The edge cases
Mid-period hire. An employee who starts on Wednesday of a bi-weekly pay period gets prorated pay. But proration of salary (daily rate = annual / 260 or annual / 365) is not standardized and affects benefit eligibility.
Multiple pay rates. An employee who works 20 hours at $15 in one department and 25 hours at $18 in another. The weighted average regular rate is ($15*20 + $18*25) / 45 = $16.67. Overtime is paid at 1.5 times $16.67, not 1.5 times either individual rate.
Supplemental wages. Bonuses can be taxed using the flat rate method (22% federal) or the aggregate method (combined with regular wages). The method used significantly affects the withholding amount.
Multi-state employees. Remote workers in a different state than their employer may owe tax in both states, with credits to avoid double taxation. Some states have reciprocity agreements. The compliance burden is enormous.
For running payroll calculations with proper tax withholding and deduction handling, I built a calculator at zovo.one/free-tools/payroll-calculator. It handles the standard cases and the common edge cases.
I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.
Top comments (0)