Building a payroll calculator or reviewing pay stubs in California means getting paycheck deductions right. Social Security, Medicare, and State Disability Insurance (SDI) can be calculated from wage rates and annual limits, which makes them well-suited for Python automation. For 2026, the Social Security Administration (SSA) sets the annual wage base at $184,500 with a 6.2% employee rate, so the maximum employee deduction is $11,439 for the year. The SSA updates this wage base every year and applies it nationwide. In 2027, the SSA projects the wage base will rise to $192,300, which would increase the maximum possible employee deduction to $11,922.60 if the rate stays the same. These numbers appear in the SSA's official actuarial and trustees reports (SSA actuarial status report, 2026 Trustees Report).
Understanding the Deduction Rules
Each deduction uses a set formula. Social Security is withheld at 6.2% of wages, but only up to a yearly wage base of $184,500 for 2026, as set by the SSA. This puts the maximum Social Security deduction for an employee at $11,439 that year. For 2027, the wage base increases to $192,300, so the maximum deduction rises to $11,922.60. The Social Security wage base is a federal rule, not a state one. Medicare applies at 1.45% of all wages with no cap. Once an employee's year-to-date wages go over $200,000, an extra 0.9% is withheld on the amount above that threshold, regardless of filing status. The federal payroll system keeps Social Security (OASDI) and Medicare financing separate, so each deduction is calculated on its own. For California SDI, the rate is 1.3% of all wages in 2026, and the Employment Development Department has announced a rate increase to 1.4% for 2027. Since 2024, SDI applies to every dollar earned, with no wage limit.
Python Implementation
To automate these calculations, a Python function can take the gross pay for a paycheck, the year-to-date wages before the current check, and the tax year. The function then applies the right rates and caps for each deduction. Here is a sample implementation:
SS_RATE, SS_WAGE_BASE = 0.062, 184_500 # 2026
MEDICARE_RATE = 0.0145
ADDL_MEDICARE_RATE, ADDL_THRESHOLD = 0.009, 200_000
SDI_RATE = {2026: 0.013, 2027: 0.014} # California EDD
def payroll_lines(gross: float, ytd_before: float, year: int = 2026) -> dict:
"""Social Security, Medicare and CA SDI for one paycheck."""
ytd_after = ytd_before + gross
ss_taxable = max(0.0, min(ytd_after, SS_WAGE_BASE) - min(ytd_before, SS_WAGE_BASE))
addl_taxable = max(0.0, ytd_after - max(ytd_before, ADDL_THRESHOLD))
return {
"social_security": round(ss_taxable * SS_RATE, 2),
"medicare": round(gross * MEDICARE_RATE + addl_taxable * ADDL_MEDICARE_RATE, 2),
"ca_sdi": round(gross * SDI_RATE[year], 2),
}This function stops Social Security deductions once the wage base is reached. Medicare and SDI continue based on their own rules. The ss_taxable variable finds the part of the current paycheck subject to Social Security, and addl_taxable finds the amount above the $200,000 Medicare threshold. The annual Social Security wage base must be tracked across year-to-date wages, not just each paycheck, to avoid over- or under-withholding as the cap is reached.
Example Calculation
Suppose an employee earns a $120,000 salary paid biweekly, which is $4,615.38 per paycheck. Using the function above, the first paycheck of the year would result in these deductions for 2026:
gross = 120_000 / 26
print(payroll_lines(gross, ytd_before=0)) # {'social_security': 286.15, 'medicare': 66.92, 'ca_sdi': 60.0}
print(payroll_lines(gross, ytd_before=0, year=2027)) # {'social_security': 286.15, 'medicare': 66.92, 'ca_sdi': 64.62}With the SDI rate going up to 1.4% in 2027, the deduction rises by about $4.62 per check at this salary, adding up to roughly $120 more over the year. For higher earners, Social Security deductions stop once the wage base is reached, but SDI continues on all wages. The Social Security wage base for 2027 is projected at $192,300, so payroll models should update this parameter each year to keep withholding accurate (SSA COLA information).
What This Model Does Not Cover
This approach covers deductions that use a straightforward formula. It does not include federal or California income tax withholding, which require more complex employer formulas and depend on the employee's tax forms. Pre-tax deductions, such as traditional 401(k) contributions or Section 125 health premiums, also affect taxable wages differently and are not included in this model.
Further Learning and Related Resources
For a more complete payroll calculation, including federal and state income tax withholding, online calculators use the full employer formulas. The California paycheck calculator referenced in the source material runs the 2026 federal tables and California's 2026 formula, showing each line item. For more Python-based financial modeling, see this earlier breakdown for practical approaches to vectorized calculations in Python.
