It’s a confusing cluster of ­leases and subleases.

The D.C. government leased a school building to a nonprofit education organization, which in turn rents the building to a public school the city operates.

And now the nonprofit is preparing to give the boot to the public school, Excel Academy, in 2021 to make way for a charter school.

“It’s entirely up to them who they want to sublet to,” Deputy Mayor for Education Paul Kihn said.

The building — once home to Birney Elementary School — highlights the complexities enveloping school real estate in a city where property is expensive and a robust charter sector is clamoring for facilities.

D.C. Public Schools had long housed Birney Elementary on the property, which sits on Martin Luther King Jr. Avenue SE, near the Anacostia Metro station. But in 2009, the school closed amid declining enrollment.

The city determined that it did not need the building for other uses and in 2011 leased it for 20 years to Building Pathways, a nonprofit organization that takes out loans to renovate buildings and leases them to charter schools, which are publicly funded but privately operated.

The city charges Building Pathways more than $700,000 in rent per year, the nonprofit confirmed.

Building Pathways said it spent millions of dollars to renovate the building and, in 2013, leased it to two charter schools: Excel Academy and Septima Clark Public Charter School.

But Excel Academy, the only public girls school in the city, expanded and eventually took over the building.

Charter schools get money from the city to cover facility costs, and Excel and Septima Clark spent 90 percent of their facilities allotment to pay rent to Building Pathways.

The city gives charters about $3,300 per student for facility costs.

In 2018, the D.C. Public Charter School Board — the agency that regulates charter schools — voted to shut down Excel Academy because of low performance.

But Excel wasn’t history just yet.

In a rare move, the traditional public school system decided to take it over.

That meant the D.C. school system had to pay rent to Building Pathways for a building the city owns.

In turn, the nonprofit organization pays rent to the city using what are known as rent credits, which it earned for spending millions of dollars to renovate the run-down building.

Now that Excel Academy is part of the traditional public school system, it is on borrowed time in the Birney building. Under terms of financing agreements, Building Pathways is required to lease the building to a charter school.

So D.C. Public Schools must secure a different building for Excel Academy by the start of the 2021-2022 school year.

“As for the future of the Birney building, in 2021 we intend to revert back to utilizing the entire building to incubate newly authorized or already established charter schools,” said Eric Rogers, the interim executive director of Building Pathways.

Shayne Wells, spokesman for D.C. Public Schools, said the city is looking for space for Excel Academy.

One small charter school already leases the bottom floor of the Birney building: an outpost of Lee Montessori.

Next year, D.C. Prep Public Charter School — a local charter network — will operate its fledgling middle school there.

And then?

“The answer to whether we’re looking at the Birney building long-term is YES,” Laura Maestas, chief executive of D.C. Prep, wrote in an email. “We are in conversations with Building Pathways and would love to sign a long-term lease on the space.”