The formula for calculating a federal pension under the Federal Employees Retirement System (FERS) is based on the employee's years of service, the average of their highest three years of salary, and a specific percentage factor determined by their age at retirement.