In 2005, Amazon rented a historic five-storey building in Luxembourg's Grund quarter, right at the bottom of a steep rock-walled valley below the old town.
By setting up in Luxembourg, and channelling sales through its units there, the world's biggest online retailer could minimise corporate taxes.
It was a move with big financial consequences.
Amazon's Luxembourg arrangements have deprived European governments of hundreds of millions of dollars in tax that it might otherwise have owed, as reported in European newspapers. But a Reuters examination of accounts filed by 25 Amazon units in six countries shows how they also allowed the company to avoid paying more tax in the United States, where the company is based.
In effect, Amazon used inter-company payments to form a tax shield for the group, behind which it has accumulated $2 billion to help finance its expansion.
Amazon revealed last year that the U.S. Internal Revenue Service (IRS) wants $1.5 billion in back taxes. The claim, which Amazon said it would "vigorously contest", is linked to its foreign subsidiaries and payments made between them.
The issue highlights the way multinationals reduce their taxes by parking intellectual property in tax havens and charging affiliates big fees for using it. Politicians in rich countries are beginning to target such practices, which have been used by other multinationals including Google and Microsoft.
U.S. Senator Carl Levin has called the tactics "gimmickry." Michael McIntyre, a tax expert at Wayne State University in Michigan, said that while Amazon's arrangement, and others like it, looked like commercial transactions, they actually only served to reduce taxes.
"The IRS shouldn't be happy about this," he said. "It sounds like they're not."
Amazon declined to answer questions about its tax affairs for this story, the latest in a Reuters series on corporate tax avoidance. In an emailed statement a spokesman said that "Amazon pays all applicable taxes in every jurisdiction that it operates within."
The group has come under scrutiny from tax departments in at least six countries over the past six years. Tax authorities in the United States, UK, Germany, France and Luxembourg declined to comment, citing rules on taxpayer confidentiality.
The Luxembourg structure, outlined by media including the Guardian newspaper in April, fulfils a corporate obligation to shareholders to maximise returns. There is no suggestion the company has broken any laws; Amazon, which started out selling books and now offers everything from tools to toys, paid an average 44 percent tax on its U.S. earnings in the last five years.
This is an examination of how Amazon set up its tax shield, and how it works.
Amazon's first foray abroad came in 1998, when it bought online retailers in Britain and Germany and rebranded them Amazon.co.uk and Amazon.de. In 2000, it launched a French website, Amazon.fr.
At first it did little to integrate these foreign units, former senior executives say. Even product purchasing - where Amazon would later squeeze huge savings by negotiating hard with suppliers - was handled independently in different markets.
"There were no real operational synergies in our early years. The units operated largely independently," said Todd Edebohls, current CEO of recruitment website Inside Jobs, and Amazon's Director of Business Development and Sales between 1999 and 2007.
But in late 1999, accounts for the UK business show, the UK unit's principal activity changed from "marketing and selling of books via the Internet" to "the provision of services to other group undertakings."
People shopping on Amazon.co.uk would now do business with a U.S. unit registered in Delaware. There were similar changes at the German business: in effect, the fast-growing European units had become fulfilment operations just to distribute packages and offer customer support. Amazon's accounts show the bulk of its overseas revenues were now attributed to the U.S. parent.
That shift helped with a problem it faced at home.
Founded in 1995 and listed two years later, the company lost money every year until 2003. This was standard practice for a dotcom startup: Amazon focused on market share rather than profit.
But by the end of 1999 Amazon's accumulated losses were so large - more than $1 billion - that its own accountants would not let the firm recognise them as a tax asset, because it was unclear it could ever make enough profit to use them up. Bringing foreign profits home allowed Amazon to set them against U.S. losses, so the company did not have to pay tax on overseas profits, according to Stephen Shay, a professor of tax law at Harvard University.
SERVICES, NOT BOOKS
That changed in 2003, when Amazon started making a lot more profit in the United States. There was a chance the foreign earnings would now increase its global tax bill, according to Shay, because U.S. corporate tax rates were higher than in other markets such as Britain.
Amazon turned to the tiny country of Luxembourg. The Grand Duchy has a population of 500,000 - half the size of Rhode Island - and offers a variety of advantages. It's a member of the European Union, so businesses based there can sell across EU borders with less red tape. Then there's the tax rate.
Luxembourg has a headline charge on corporate income of 29 percent, but under certain circumstances it will exempt income a company earns through intellectual property by up to 80 percent, a government spokesperson said. This cuts the effective tax rate to below 6 percent. Tax advisers and academics say rates close to zero can be achieved using other methods.
In June 2003, Amazon registered Amazon Services Europe SARL in Luxembourg, establishing an office in a drab grey concrete building overlooking the central bus depot. The initials stand for Societe a Responsabilite Limitee - a limited company, liable for tax.
A month later, it told clients in the UK its terms were changing. Contracts with third-party retailers who used Amazon to sell their products would no longer be handled in the United States but with the Luxembourg unit.
In June 2004, Amazon established another Luxembourg entity - Amazon Europe Holding Technologies - whose purpose was to hold shares in Amazon group companies and "to acquire ... any intellectual property rights, patents, and trademarks licences and generally to hold, to license the right to use it solely to one of its direct or indirect wholly owned subsidiaries."
This group was set up as a "Societe en Commandite Simple" or SCS, a type of limited partnership that a Luxembourg government spokesman said is exempt from income taxes. It has not had any operational staff or premises, its registered address being the offices of a trust services company in an upmarket residential area west of Luxembourg's old town.
A month later, this company established a third Luxembourg company, Amazon EU SARL, whose principal purpose was to "sell, auction, rent or otherwise distribute products or services of all types" via Amazon websites.
This taxable unit was to become, on paper at least, the supplier of all goods and services to Amazon's European customers.
FROM NEVADA TO LUXEMBOURG
To be tax efficient, though, Amazon needed to shift the profit this unit would make into its untaxed parent. The easiest way to do this was for Amazon EU SARL to pay Amazon Europe Holding Technologies a fee to license the Amazon technology it would use to sell things.
There was just one problem: Amazon Europe Holding Technologies had no technology to license. Amazon's patents - including the Amazon brand and its '1-click' ordering software - were held by Amazon Technologies Inc, a unit registered in Nevada, Patent and Trademark Office records show.
In early 2005, Amazon did an inter-company deal that solved this problem.
Exact details of the arrangement have never been made public and Amazon declined to clarify them. Chief Financial Officer Tom Szkutak told analysts on a conference call a few weeks afterwards that the deal to create the Luxembourg operation involved shifting "certain operating assets" offshore and that it would boost the group's 2005 tax bill by $58 million but "beneficially impact our effective tax rate over time."
Amazon's Luxembourg arrangements have helped it pay an average tax rate of 5.3 percent on overseas income over the past five years, less than a quarter of the average rate across its major foreign markets.
Company accounts show that since 2005, Amazon Europe Holding Technologies started to make payments to Amazon Technologies Inc in Nevada of up to 230 million euros each year. At the same time it received up to 583 million euros each year from its European affiliates.
The difference stayed in Luxembourg.
Had Amazon remitted all that to the United States and then paid the headline U.S. corporate income tax rate on it, the firm would have incurred taxes of more than $700 million. But it has not and the deal has allowed Amazon's Luxembourg unit to accrue tax-free cash worth more than $2 billion.
Historically, such inter-company payments might have been treated as a taxable dividend under U.S. tax law, but a provision introduced in 1997 known as 'check-the-box' allowed companies to have them disregarded by the IRS. Senator Levin, a Democrat, is among many U.S. politicians who want this loophole rescinded.
"HEADQUARTERS OF NIGHT LIFE"
For Amazon's tax-free money-making machine to work, it had to show it had more than a nameplate in Luxembourg.
To benefit from favourable taxation, the Grand Duchy says firms "must ensure that they give adequate substance to their presence in the country in terms of both logistics and staff." At the end of 2005, Amazon had just a dozen staff there. If tax departments around the continent were to recognise the arrangement, Amazon needed a meaningful corporate presence.
In February 2006, it transferred ownership of its UK, German and French businesses to Amazon EU SARL, and ownership of its UK and French web domains to Amazon Europe Holding Technologies. It also moved some U.S. executives to Luxembourg, hired more locals and began to call Amazon EU its European headquarters.
Filings show that in December 2006, the group relocated its Luxembourg operating units into the rented building on Plaetis Steet, a stone's throw from the English and Irish bars that lead the city-state's tourist office to describe the Grund and neighbouring Clausen as the "Headquarters of Luxembourg's night life."
CASH PILE BUILDS
As the cash built up in Amazon Europe Holding Technologies, the firm started to lend to Amazon EU SARL. Besides funding international expansion, this has generated up to 45 million euros a year in interest since 2005 - all untaxed.
Today, Amazon calls its 300-person Luxembourg operation the nerve-centre of an operation which employs tens of thousands of people across the continent. It expanded into a new building, opened by Luxembourg's Finance Minister, Luc Frieden, in October.
"All the strategic functions for our business in Europe are based in Luxembourg," Amazon's head of public policy, Andrew Cecil, told UK parliamentarians in November.
At home in the United States, though, the Internal Revenue Service seems unconvinced.
Amazon disclosed in October 2011 that the IRS wanted $1.5 billion in unpaid taxes. It has declined to say exactly what transactions the charge relates to but said it was linked to "transfer pricing with our foreign subsidiaries" over a seven-year period from 2005.
"We disagree with the proposed adjustments and intend to vigorously contest them," Amazon said at the time. "If we are not able to resolve these proposed adjustments ... we plan to pursue all available administrative and, if necessary, judicial remedies."
Shay, the Harvard professor who contributed to a recent Congressional committee investigating tax avoidance, said the fact the Luxembourg unit charged a much higher price than it paid for the right to license Amazon intellectual property could open the company to an investigation into whether it is engaging in abusive transfer pricing.
"The price originally paid to the U.S. for the rights is something the IRS should want to look at," he said.
Transfer pricing is the way corporations trade goods or services between their units. Many multinationals use it.
The Organisation for Economic Co-operation and Development, which lays down the rules on transfer pricing, stipulates that it should not be used to shift profits from high tax jurisdictions to low tax jurisdictions.
The IRS declined to comment.