The 5-4 ruling Thursday is a win for states, who...

New Yorkers will soon have nowhere to hide from the steep sales tax.

The state can now force all online retailers to collect the 8.875 percent combined state and city sales tax on purchases made by Big Apple residents, according to a US Supreme Court ruling Thursday.

The 5-4 decision overturned the 1992 Quill Corp.-vs.-North Dakota ruling, which found states could not require out-of-state retailers to collect sales tax if they had no “physical presence” in the state.

That means New Yorkers will have to add the tax on more than half of all Amazon purchases that are now tax-free.

States were losing out on an estimated $8 billion to $33 billion in revenue as a result of the Quill ruling, according to Thursday’s opinion, written by Justice Anthony Kennedy.

Mail-order sales totaled around $180 billion in 1992 — today, online sales account for $453.5 billion alone, and traditional mail-order revenues push that figure past a half-trillion dollars, according to the ruling.

“Quill puts both local businesses and many interstate businesses with physical presence at a competitive disadvantage relative to remote sellers,” Kennedy wrote. “Remote sellers can avoid the regulatory burdens of tax collection and can offer de facto lower prices caused by the widespread failure of consumers to pay the tax on their own.”

The decision could generate “hundreds of millions of dollars” in new revenue for New York state, according to Joseph Bishop-Henchman, vice president of the Tax Foundation think tank.

The state Department of Finance could not say how much New York was losing under the old ruling — or when it would enact new regulations to take advantage of the new ruling.

“We’re reviewing the decision,” was all agency rep James Gazzale said in an emailed statement.

Big Apple online shoppers were technically supposed to pay the sales tax themselves if a retailer did not collect it. “Nobody does it, but they actually technically do owe it,” said Howard Gleckman of the Tax Policy Institute. “So, if you’re a tax cheat, this isn’t good for you.”

Some popular “e-tailers” already collected at least some state sales tax.

Amazon adds the fee for all items it sells directly, though an estimated 52 percent of its sales come from third-party vendors not required to remit taxes.

Two popular companies named in the Supreme Court decision — home-goods retailer Overstock.com and electronics merchant Newegg.com — currently collect no New York sales tax because they have no physical offices here.

The ruling could create a serious legal headache for smaller businesses, according to a dissenting opinion from Chief Justice John Roberts.

“Correctly calculating and remitting sales taxes on all e-commerce sales will likely prove baffling for many retailers,” he wrote.

Thursday’s decision came after South Dakota passed a law in 2016 compelling remote retailers to collect sales taxes and then sued several merchants to pay up.

States such as South Dakota, which have no income tax and rely heavily on sales taxes, stand to gain the most from the new ruling, according to a Barclays research note.

Louisiana, Tennessee, South Dakota, Oklahoma and Alabama all stand to reap the highest gains as a percentage of their current revenue, the research found.

With Post wires