Over the past decade Canadian Pacific paid just $138 million in cash taxes—which amounts to just 2% of its pre-tax profits. This was considerably lower than the other major Canadian railroad, CN Rail, which itself enjoyed an enviable rate of 19%.

To understand why, let’s start with a history lesson. Way back in the late 19th century, Sir Charles Tupper (then minister of railways and canals) entered into a contract with CP as a means of getting a railway built to British Columbia. Clause 16 of that contract contained the following provision:

That the Canadian Pacific Railway Company shall be forever free from taxation by the Dominion….

Forever hasn’t expired yet—not even 134 years later. According to one court’s recent interpretation, this generous exemption applies only to CP’s operations as they were contemplated in 1880. But it has lost none of its potency: recently CP contested certain fuel and corporate taxes the Canada Revenue Agency compelled it to pay on its so-called exempt main line. CRA asked the Federal Court to strike the claim, arguing CP was trying to circumvent the tax system. But the court allowed CP’s claim to proceed. It noted that the contract might mean “that the CPR does not bear the economic burden of any taxation nor is it subject to the procedural burdens and limitations contained within the taxation regime.” Few companies can say that.

CP still puts considerable thought into other ways to maximize its tax efficiency. It made extensive use of tax losses from previous years to reduce balances owing during the early and mid-2000s. The company had $800 million in carry-forwards available for this purpose at the beginning of the 10-year period covered by our data. CP warned investors it would eventually exhaust that tax-loss arsenal and begin paying more cash taxes. And yet, in 2009 it received a net cash tax refund of nearly $39 million. What happened?

Part of the explanation lies in CP’s profits falling dramatically during the recession. But there’s something else. In 2009 CP began making aggressive prepayments into its pension plans. Over the next three years it contributed $1.75 billion more than required. Much of that sum was borrowed “at very attractive interest rates.” Under the Income Tax Act, such pension contributions are tax deductible. The taxes avoided likely outweigh the borrowing costs.

CP has also availed itself of tax credits, including for track maintenance. Its lengthy tax holiday may be coming to an end; CP recently reported its cash taxes for 2013 owing at $31 million.