When Jeff Bezos was looking for a home for his fledgling online bookseller, amazon.com, in 1994, his first choice is said to have been a Native American reservation. The location would have presented generous tax breaks if the state of California had not intervened and halted the plan.

Next stop was Seattle, which Bezos said he selected because Washington state had – among other things – a smallish population. At the time only those retailers with a physical presence in a state paid sales taxes, so a home state with a small population meant the lowest possible sales tax burden. Sales made into other more populous states would not be taxed.

It was a strategic decision that would characterise Amazon’s attitude towards paying tax over the next two decades. Its critics allege that it owes its position as the world’s largest online retailer in part to its use of contrived and artificial tax arrangements that – while legal – endow it with competitive advantages no bricks-and-mortar retailer could ever hope to enjoy.

The company deployed the strategy in Luxembourg, the tiny European country that became, in the words of the Tax Justice Network, “the Death Star of financial secrecy” in a national bid to attract capital through tax competition.

The architect of that transformation, Jean-Claude Juncker, later became the president of the European commission, and has been dogged by questions about his suitability for the post in an atmosphere of increasing anger about tax avoidance ever since.

Amazon first arrived in Luxembourg in 2003, and within a few months secured a confidential agreement with the country’s tax authorities. Bob Comfort, Amazon’s head of tax, would later tell the Luxembourgish newspaper d’Lëtzebuerger Land that Juncker had personally offered to help Amazon. “His message was simply: ‘If you encounter problems which you don’t seem to be able to resolve, please come back and tell me. I’ll try to help.’” Comfort was later appointed Luxembourg’s “honorary consul to Seattle”, the location of Amazon’s US headquarters.

Fast-forward a decade, and Amazon would find itself in the crosshairs of Europe’s competition commissioner, Margrethe Vestager, best known for her ruling that Apple enjoyed €13bn of illegal state aid from Ireland in the form of preferential tax treatment. Her investigation into Amazon would focus on the nature of its secret deal with Luxembourg. But the details of that deal would be revealed not as a result of her inquiry, but by a parallel investigation by the Internal Revenue Service in the US.

The tax strategy, internally codenamed Project Goldcrest after the national bird of Luxembourg, was fundamental to Amazon’s plan to put the duchy at the heart of the European business of its global empire. Though highly complicated, at its core the scheme involved the following interplay between entities in Luxembourg and the US:

1. Amazon Europe Holding Technologies SCS (AEHT) would own the legal right to use Amazon’s intellectual property, or IP, outside the United States. Because it was a specific type of legal entity, called a “non-resident partnership”, any money it received from other Amazon entities in exchange for the right to use that IP would be tax-free.

2. Amazon EU Sarl, which operates Amazon’s European businesses, would pay AEHT hundreds of millions of euros in “royalty fees” for that IP each year. The cost of the royalties would be offset against its own tax bill.

3. AEHT would pay Amazon’s US business its own royalty fees for the right to license out that IP in Europe.

While EU regulators argued that the royalties between the two Luxembourg companies were too high, US regulators argued the royalties paid back to Amazon’s American headquarters were too low. The net effect of the baroque Project Goldcrest was to reduce Amazon’s taxes everywhere.

Last year the EU ordered Amazon to repay €250m in “illegal tax advantages” following its investigation, and last month the European commission proposed a new 3% “digital tax” on the revenues (rather than profits) of large technology companies – to prevent them avoiding taxes by shifting their profits around the globe.

In the UK, campaigners have long held suspicions that HM Revenue and Customs selects which taxpayers to pursue for alleged underpayment according to political expediency. HMRC has always denied these claims, and says it treats all taxpayers equally according to the law. But those allegations were made substantially more credible two months ago, when a VAT campaigner released a covert recording of his off-the-record conversation with an HMRC official in the pub. The subject of their discussion: Amazon. “I’ve heard from the Treasury; the Treasury didn’t want us to be too hard on Amazon,” the official said, before adding “but I think that was ‘yet’”. HMRC did not respond to the specifics of the recording, but reiterated that it “has not been told to be soft on multinationals and no taxpayer gets preferential treatment”.

A student at the University of Alabama pushes a large Amazon Dash button, which was part of Birmingham’s campaign to lure Amazon’s second headquarters. Photograph: Brynn Anderson/AP

More recently Donald Trump has repeatedly accused Amazon of underpayment of taxes – although the US president has previously bragged that paying little to no tax made him “smart”, and his grudge against the company is likely to be partly motivated by his hatred of the Bezos-owned Washington Post. But one focus of Trump’s attacks, an arrangement between Amazon and the United States Postal Service, which the president alleges is unfairly generous, is emblematic of the company’s strategy of haggling with public authorities.

Amazon is presently inviting US cities to outbid each other in a contest to host its “second headquarters”, waving the promise of 50,000 jobs and $5bn of investment in front of the winning applicant. Maryland offered $5bn of tax incentives – dollar for dollar the same as the pledged investment – for the company to opt for Montgomery County, while California offered between $300m and $1bn of breaks. New Jersey even promised $7bn of tax incentives – $2bn more than Amazon’s maximum investment. Whichever city wins, it seems likely that tax will influence its decision-making: the firm’s published criteria for bidders specifically cites “a stable and business-friendly environment and tax structure” as a high priority.

• This article was amended on 26 April 2018 to clarify the source of our assertion about why Amazon based itself in Washington state.