DEV Community

Mizan Labs
Mizan Labs

Posted on Edited on AI-assisted

How Moroccan payroll is actually calculated (with a worked example and code)

If you build HR, payroll or accounting software for Morocco, the salary maths looks simple until you write it. Social contributions have a ceiling, the professional-expenses deduction changes rate at a threshold, income tax is progressive on an annual base, and the family deduction changed in 2026. Here is the full calculation for one employee, step by step, on the 2026 rules.

The example

A private-sector employee earning 10,000 MAD gross per month, with 2 dependants, no pension top-up (CIMR) and no private health insurance.

Step 1: employee social contributions

  • CNSS: 4.48 %, but only on the first 6,000 MAD of monthly salary. 6,000 × 4.48 % = 268.80 MAD
  • AMO (health insurance): 2.26 % of the full gross, no ceiling. 10,000 × 2.26 % = 226.00 MAD

The ceiling is the first trap: a naive gross * 0.0448 overcharges anyone above 6,000 MAD.

Step 2: professional expenses (frais professionnels)

A flat deduction before income tax:

  • 35 % if annual taxable gross is 78,000 MAD or less
  • 25 % above that, capped at 35,000 MAD a year

Here the annual gross is 120,000 MAD, so 25 %: 10,000 × 25 % = 2,500 MAD (the cap of 2,916.67 a month is not reached).

Step 3: net taxable salary

10,000 − 2,500 − 268.80 − 226.00 = 7,005.20 MAD a month, i.e. 84,062.40 MAD a year.

Step 4: income tax (IR), progressive on the annual amount

2026 brackets:

Annual net taxable income (MAD) Rate
0 – 40,000 0 %
40,001 – 60,000 10 %
60,001 – 80,000 20 %
80,001 – 100,000 30 %
100,001 – 180,000 34 %
above 180,000 37 %

For 84,062.40: 20,000 × 10 % + 20,000 × 20 % + 4,062.40 × 30 % = 2,000 + 4,000 + 1,218.72 = 7,218.72 MAD a year, or 601.56 a month.

Step 5: family deduction

Since 2026: 600 MAD per dependant per year, up to 6 dependants. 2 × 600 = 1,200 a year = 100 MAD a month. IR = 601.56 − 100 = 501.56 MAD.

Step 6: net pay

10,000 − 268.80 − 226.00 − 501.56 = 9,003.64 MAD

And what the employer pays on top

Contribution Rate Base MAD
CNSS social benefits 8.98 % first 6,000 538.80
Family allowances 6.40 % full gross 640.00
Vocational training tax 1.60 % full gross 160.00
AMO 2.26 % full gross 226.00
AMO solidarity 1.85 % full gross 185.00
Total 1,749.80

Total employer cost: 11,749.80 MAD for a 9,003.64 MAD net salary.

In code

The core of it fits in a few lines (rates as data, never hard-coded in the formula):

const cnss = Math.min(gross, 6000) * 0.0448;
const amo = gross * 0.0226;
const fp = gross * 12 <= 78000 ? gross * 0.35 : Math.min(gross * 0.25, 35000 / 12);
const taxable = (gross - fp - cnss - amo) * 12;
const brackets = [[40000, 0], [60000, 0.1], [80000, 0.2], [100000, 0.3], [180000, 0.34], [Infinity, 0.37]];
let ir = 0, lower = 0;
for (const [top, rate] of brackets) { if (taxable > lower) ir += (Math.min(taxable, top) - lower) * rate; lower = top; }
ir = Math.max(0, ir - Math.min(dependents, 6) * 600) / 12;
const net = gross - cnss - amo - ir;
Enter fullscreen mode Exit fullscreen mode

The hard part is not this function. It is keeping every rate right when the Finance Law changes, and handling the rest: net to gross (you need an inverse), CIMR, exempt allowances, severance by service band, notice periods, paid leave, final settlement.

Sources

  • Income tax brackets, professional expenses, family deduction: General Tax Code 2026 and Finance Law 50-25 (BO 7465 bis).
  • CNSS rates and the 6,000 MAD ceiling: decree 2-01-2723 (consolidated). AMO: decree 2-05-734 as amended by 2-14-707. Training tax: decree 2-73-633.

If you'd rather not maintain it

I packaged this engine as a small JSON API, with every rate's source and last-verified date in the response: gross↔net, employer cost, IR breakdown, severance, leave and final settlement. It has a free plan (100 calls a month): https://mizanlabs.devsupex.app/payroll-api The same engine runs free calculators in French at https://salaire.devsupex.app if you want to check a case by hand.

Estimates for private-sector employees; not legal or tax advice. If you spot a mistake, tell me and I'll fix it.

Top comments (0)