Following Canadian Confederation, the creation of the Canadian Pacific Railway was a task originally undertaken as the "National Dream" by the Conservative government of Prime Minister John A. Macdonald (1st Canadian Ministry). A key component of his National Policy, Macdonald was helped by Alexander Tilloch Galt, who was the owner of the North Western Coal and Navigation Company. British Columbia, a four-month sea voyage away from the East Coast, had insisted upon a land transport link to the East as a condition for joining Confederation, after initially requesting a wagon road.

1872–1881

In 1873, John A. Macdonald and other high-ranking politicians, bribed in the Pacific Scandal, granted federal contracts to Hugh Allan's Canada Pacific Railway Company (unrelated to the current company) rather than to David Lewis Macpherson's Inter-Ocean Railway Company which was thought to have connections to the American Northern Pacific Railway Company. Because of this scandal, the Conservative Party was removed from office in 1873. The new Liberal prime minister, Alexander Mackenzie, ordered construction of segments of the railway as a public enterprise under the supervision of the Department of Public Works led by Sandford Fleming. Surveying was carried out during the first years of a number of alternative routes in this virgin territory followed by the construction of a telegraph along the lines that had been agreed upon. The Thunder Bay section linking Lake Superior to Winnipeg was commenced in 1875. By 1880, around was nearly complete, mainly across the troublesome Canadian Shield terrain, with trains running on only of track.

With Macdonald's return to power on 16 October 1878, a more aggressive construction policy was adopted. Macdonald confirmed that Port Moody would be the terminus of the transcontinental railway, and announced that the company would follow the Fraser and Thompson rivers between Port Moody and Kamloops. In 1879, the federal government floated bonds in London and called for tenders to construct the section of the railway from Yale, British Columbia, to Savona's Ferry, on Kamloops Lake. The contract was awarded to Andrew Onderdonk, whose men started work on 15 May 1880. After the completion of that section, Onderdonk received contracts to build between Yale and Port Moody, and between Savona's Ferry and Eagle Pass.

On 21 October 1880, a new syndicate, unrelated to Hugh Allan's, signed a contract with the Macdonald government. Fleming was dismissed and replaced with Collingwood Schreiber as chief engineer and general manager of all government railways. They agreed to build the railway in exchange for $25 million (approximately $625 million in modern Canadian dollars) in credit from the Canadian government and a grant of of land. The government transferred to the new company those sections of the railway it had constructed under government ownership, on which it had already spent at least $25 million. But its estimates of the cost of the Rocky Mountain section alone was over $60 million. The government also defrayed surveying costs and exempted the railway from property taxes for 20 years. The Montreal-based syndicate officially comprised five men: George Stephen, James J. Hill, Duncan McIntyre, Richard B. Angus and John Stewart Kennedy. Donald A. Smith and Norman Kittson were unofficial silent partners with a significant financial interest. On 15 February 1881, legislation confirming the contract received royal assent, and the Canadian Pacific Railway Company was formally incorporated the next day. Critics claimed that the government gave too large a subsidy for the proposed project but this was to incorporate uncertainties of risk and irreversibility of insurance. The large subsidy also needed to compensate the CPR for not constructing the line in the future, but rather right away even though demand would not cover operational costs.

A beaver was chosen as the railway's logo in honour of Donald Smith, 1st Baron Strathcona and Mount Royal, who had risen from factor to governor of the Hudson's Bay Company over a lengthy career in the beaver fur trade. Smith was a principal financier of the CPR. staking much of his personal wealth to the venture. In 1885, he drove the last spike to complete the transcontinental line.

Building the railway, 1881–1886

Building the railway took over four years. James J. Hill in 1881 sent Alpheus Beede Stickney to serve as construction superintendent for the Canadian Pacific Railway. The Canadian Pacific Railway began its westward expansion from Bonfield, Ontario (previously called Callander Station), where the first spike was driven into a sunken railway tie. Bonfield was inducted into Canadian Railway Hall of Fame in 2002 at the CPR first spike location. That was the point where the Canada Central Railway extension ended. The CCR was owned by Duncan McIntyre, who amalgamated it with the CPR, and became one of the handful of officers of the newly formed CPR. The CCR started in Brockville and extended to Pembroke. It then followed a westward route along the Ottawa River passing through places like Cobden, Deux-Rivières, and eventually to Mattawa at the confluence of the Mattawa and Ottawa rivers. It then proceeded cross-country towards its final destination of Bonfield. Duncan McIntyre and his contractor James Worthington piloted the CPR expansion. Worthington continued on as the construction superintendent for the CPR past Bonfield. He remained with the CPR for about a year after which he left the company. McIntyre was uncle to John Ferguson who staked out future North Bay and who became the town's wealthiest inhabitant and mayor for four successive terms.Berton, Pierre. "The Last Spike: The Great Railway 1881–1885". McClelland and Stewart Limited, Toronto. 1971, p. 280

It was presumed that the railway would travel through the rich "Fertile Belt" of the North Saskatchewan River Valley and cross the Rocky Mountains via the Yellowhead Pass, a route suggested by Fleming based on a decade of work. However, the CPR quickly discarded this plan in favour of a more southerly route across the arid Palliser's Triangle in Saskatchewan and via Kicking Horse Pass and down the Field Hill to the Rocky Mountain Trench. This route was more direct and closer to the Canada–US border, making it easier for the CPR to keep American railways from encroaching on the Canadian market. However, this route also had several disadvantages.

One was that the CPR would need to find a route through the Selkirk Mountains in British Columbia. At the time, it was not known whether a route even existed. The job of finding a pass was assigned to surveyor Major Albert Bowman Rogers. The CPR promised him a cheque for $5,000 and that the pass would be named in his honour. Rogers became obsessed with finding the pass that would immortalize his name. He discovered the pass in April 1881 and, true to its word, the CPR named it "Rogers Pass" and gave him the cheque. However, he at first refused to cash it, preferring to frame it, saying he did not do it for the money. He later agreed to cash it with the promise of an engraved watch.

Another obstacle was that the proposed route crossed land in Alberta that was controlled by the Blackfoot First Nation. This difficulty was overcome when a missionary priest, Albert Lacombe, persuaded the Blackfoot chief Crowfoot that construction of the railway was inevitable. In return for his assent, Crowfoot was famously rewarded with a lifetime pass to ride the CPR.

A more lasting consequence of the choice of route was that, unlike the one proposed by Fleming, the land surrounding the railway often proved too arid for successful agriculture. The CPR may have placed too much reliance on a report from naturalist John Macoun, who had crossed the prairies at a time of very high rainfall and had reported that the area was fertile.Lamb, W. Kaye. "History of the Canadian Pacific Railway". Macmillan Publishing Co., Inc., New York (1977), p. 79.

The greatest disadvantage of the route was in Kicking Horse Pass, at the Alberta-British Columbia border on the continental divide. In the first west of the high summit, the Kicking Horse River drops . The steep drop would force the cash-strapped CPR to build a long stretch of track with a very steep 4 percent gradient once it reached the pass in 1884. This was over four times the maximum gradient recommended for railways of this era, and even modern railways rarely exceed a two-percent gradient. However, this route was far more direct than one through the Yellowhead Pass and saved hours for both passengers and freight. This section of track was the CPR's Big Hill. Safety switches were installed at several points, the speed limit for descending trains was set at 10 km per hour (6 mph), and special locomotives were ordered. Despite these measures, several serious runaways still occurred including the first locomotive, which belonged to the contractors, to descend the line. CPR officials insisted that this was a temporary expediency, but this state of affairs would last for 25 years until the completion of the Spiral Tunnels in the early 20th century.

In 1881, construction progressed at a pace too slow for the railway's officials who, in 1882, hired the renowned railway executive William Cornelius Van Horne to oversee construction with the inducement of a generous salary and the intriguing challenge of handling such a difficult railway project. Van Horne stated that he would have of main line built in 1882. Floods delayed the start of the construction season, but over of main line, as well as sidings and branch lines, were built that year. The Thunder Bay branch (west from Fort William) was completed in June 1882 by the Department of Railways and Canals and turned over to the company in May 1883, permitting all-Canadian lake and railway traffic from Eastern Canada to Winnipeg for the first time. By the end of 1883, the railway had reached the Rocky Mountains, just eight kilometres (five miles) east of Kicking Horse Pass. The construction seasons of 1884 and 1885 would be spent in the mountains of British Columbia and on the north shore of Lake Superior.