If you work in the UAE as a developer, you have probably done this maths at least once: leaving a job, opening a spreadsheet, and trying to work out your end-of-service gratuity.
The formula looks simple. The bugs are in the inputs. I built a free UAE gratuity calculator to handle it, and this post is the logic behind it — the rules, the edge cases, and the two numbers everyone confuses.
The rules, as code
Under Federal Decree-Law No. 33 of 2021, a foreign employee in the UAE private sector qualifies for gratuity after at least one year of continuous service.
The formula, in pseudocode:
dailyBasic = basicSalary / 30
if years <= 5:
gratuity = dailyBasic * 21 * years
else:
gratuity = dailyBasic * 21 * 5 + dailyBasic * 30 * (years - 5)
That is the whole calculation. Three inputs matter: basicSalary, years (including part-years), and unpaid leave days, which are deducted from the service period.
In JavaScript, the core looks like this:
function calculateGratuity(basicSalary, years) {
const daily = basicSalary / 30;
if (years <= 5) return daily * 21 * years;
return daily * 21 * 5 + daily * 30 * (years - 5);
}
Simple — until you feed it the wrong basicSalary.
Bug #1: total salary instead of basic salary
This is the most common error, and it is an input bug, not a formula bug.
Gratuity is calculated on basic salary only. Housing, transport and other allowances are excluded, however large they are.
If a developer earns AED 19,000 total with a basic of AED 9,500, the correct input is 9,500, not 19,000. Plug in the total and you will expect roughly double the correct figure — then blame the employer when the settlement comes in lower.
The fix is boring but essential: read the basic salary from the contract or payslip, and if it is not stated separately, get it from HR in writing before you calculate anything.
Bug #2: the wrong divisor
There are two different "daily" figures, and they are used for different things:
Daily pay = total monthly salary ÷ 26 working days
Daily basic wage for gratuity = basic salary ÷ 30
Use 26 where 30 belongs, or vice versa, and the result is wrong by about 15%. A calculator that does not make this distinction explicit is a calculator that will mislead people.
This is also why a generic "salary ÷ 26" gratuity formula borrowed from another country — India uses 26 — gives a wrong answer for the UAE. The UAE daily wage for gratuity uses 30.
Worked examples (with the code above)
Example 1: 5 years, basic AED 9,500
daily = 9500 / 30 = 316.67
per year = 316.67 * 21 = 6,650
total = 6,650 * 5 = AED 33,250
Example 2: 6 years, basic AED 15,500
daily = 15500 / 30 = 516.67
first 5 years = 516.67 * 21 * 5 = 54,250
year 6 = 516.67 * 30 = 15,500
total = AED 69,750
The step change at year five is the interesting part of the function: the rate jumps from 21 to 30 days, a ~43% increase. That is why the exact last working day matters — the function is discontinuous at the five-year boundary, and a few months either side can be worth thousands of dirhams.
Edge cases worth handling
Less than 1 year of service: gratuity is normally zero. Return 0, do not return a pro-rated figure.
Unpaid leave: deduct those days from the service period before calculating. Paid annual leave, sick leave and maternity leave do not reduce it.
Resignation: under the old law, resigning could reduce gratuity to one-third or two-thirds. Under the current law, that reduction does not apply in the same way — an employee with at least one year of service is generally entitled on the same basis whether they resign or the contract ends another way.
Contract type: the old limited vs unlimited distinction is gone. Since 2022, UAE contracts are fixed-term, usually up to three years and renewable. Contract type should not change the formula.
Payment deadline: the employer must pay within 14 days of the contract ending. If payment is late, the employee should raise it with HR in writing, then with MOHRE (Ministry of Human Resources and Emiratisation) if needed.
Why I built it as a tool, not a spreadsheet
A spreadsheet works once. A calculator works every time, for anyone, with no formula to break. The inputs are three fields — basic salary, joining date, last working day — and the output is the breakdown: the 21-day part, the 30-day part, and the total, so the user can compare it line by line with their employer's settlement.
That breakdown is the point. A single total tells you nothing. A breakdown lets you spot whether the employer's basic salary or service dates differ from yours — which is where almost every dispute actually lives.
Takeaway
The UAE gratuity formula is five lines of code. The hard part is the inputs: the correct basic salary, the correct service period, and the correct divisor.
Get those three right, and the maths takes care of itself. Get one wrong, and no amount of spreadsheet formatting will save the result.
If you are leaving a job in the UAE, run the numbers yourself before you sign anything. A few minutes of checking now can save you thousands of dirhams later.
This article is a general guide, not legal advice. Employment law and individual contracts vary, so for a disputed or unusual case, check with MOHRE or a qualified legal adviser in the UAE.
About the author: Jawad Awan is the creator of DirhamTools, a free set of UAE calculators for gratuity, final settlement, salary, VAT, rent and visa costs.


