They are masters of the fat paycheck.

The headmasters of New York City’s toniest private schools are raking in salaries, bonuses and benefits up to $1 million — five times what the leaders of the city’s best public high schools get annually.

Many also get perks like free housing, housekeeping, or reimbursement for gym and country-club dues.

Topping the list of elite earners is Bruce Dennis, head of school at the Packer Collegiate Institute in Brooklyn, whose total 2016 compensation came to $1,002,643, including base pay of $702,450 and a $186,656 payout from his retirement plan, according to the school’s latest tax filing.

The Brooklyn Heights school enrolls about 1,000 students in grades K-12, charged tuition in 2017-18 ranging from $43,700 to $44,700 and counts “Good Day New York” anchor Rosanna Scotto and “True Blood” actress Deborah Ann Woll among its alumni. Its Gothic buildings also served as a set for “Gossip Girl.”

Close behind Dennis was Thomas Kelly, head of school at Horace Mann, whose total 2016 compensation came to $996,136, including base pay of $951,498.

The Riverdale, The Bronx, school, whose graduates include Eliot Spitzer and Jack Kerouac, has been rocked in recent years by revelations of past sexual abuse of students by faculty, prompting Kelly and the school’s board chairman in 2013 to issue an apology letter.

Kelly received a 14 percent pay hike over the previous year, tax filings show. He heads a school with 1,791 students in nursery through 12th grade. Tuition in 2017-18 was $48,600.

Most of the city’s private schools operate as nonprofits and are required by law to make public their tax documents listing revenue, expenses and the salaries of the highest-paid employees.

Schools like the Friends Seminary, Ramaz School, and Convent of the Sacred Heart are not required to file IRS returns because they are religious organizations, so their spending and salaries remain secret.

And a handful of schools like the Dwight School and Avenues are for-profit corporations and don’t have to disclose their finances.

The tax filings also shed light on how much money the schools bring in through donations and on their sky-high endowments.

The all-girls Brearley School on the Upper East Side, which Caroline Kennedy attended, got a $4 million contribution in 2016-17 as well as a $2.5 million donation and one for $2.1 million, according to its tax filing. Tuition at the K-12 school, which enrolls about 720 students, is $49,680.

A Brearley spokeswoman would not reveal the donors’ identities. The school’s endowment stood at $60 million at the end of last June. Its head of school, Jane Foley Fried, pulled down $793,199 in compensation.

The Dalton School on the Upper East Side, which enrolls about 1,300 students and charges $48,450 in tuition and includes Anderson Cooper and actress Jennifer Grey among its famed alumni, received donations of $2.2 million and $2.5 million in the year ending June 30, 2017, as well as three donations of $1 million each. The donors were not disclosed.

Ellen Stein, who headed the school until last month, raked in $813,206 in total compensation in 2016. Dalton’s endowment was $101.8 million at the end of the last school year.

Patricia Hayot, who earned $765,789 in 2016 as head of the all-girls Chapin School in Yorkville, — which enrolls nearly 800 students and educated Jacqueline Kennedy Onassis and Ivanka Trump — has received among the richest perks. The school provided a $500,000 loan in 2006 so she could purchase a $2 million Upper East Side condo.

Public records show Hayot lives elsewhere in the neighborhood and rents out the two-bedroom apartment for $7,400 a month.

As of June 2017, Hayot had made no payments on the loan, which was to be repaid by 2014, according to the school’s tax filing and mortgage documents, which show all the rental income was to go to the school.

Hayot and a Chapin spokeswoman did not return requests for comment.

The top educator’s salary is a lot lower at an elite public school.

Jean Donahue was paid $161,593 last year as principal of the Bronx HS of Science, which has nearly 3,000 students and is ranked the 57th best high school in the country by US News & World Report.

Even at the lower end of the pay scale, the private-school directors are earning hundreds of thousands more than New York City’s public school principals, whose top earners were paid $166,148 in 2016.