The Saudi formula, in plain words
Contract end or termination: half a month's wage for each of the first 5 years, plus one full month's wage for every year after that.
Resignation: you receive a fraction of that amount — nothing under 2 years, one-third from 2 to 5 years, two-thirds from 5 to 10 years, and the full award after 10 years. (Separate rules cover resignation by a woman within 6 months of marriage or 3 months of childbirth, and force majeure — check those cases with HRSD.)
Worked example
Last wage SAR 10,000, service 7 years, contract ended: first 5 years = 5 × 5,000 = SAR 25,000; next 2 years = 2 × 10,000 = SAR 20,000; total SAR 45,000. The same worker resigning gets two-thirds: SAR 30,000. Try both above.
Important notes
The award is calculated on your last wage. The official HRSD/Qiwa end-of-service calculator gives the authority's own figure for your exact record — use this tool to understand and check it, and raise any difference with your employer's HR in writing before you sign a final settlement.