Exhibit 5.1
Consent of Independent Registered Public Accounting Firm
The Board of Directors
Canadian National Railway Company:
We consent to the use of our report dated February 4, 2026, on the consolidated financial statements of Canadian National Railway Company, which comprise the consolidated balance sheets as at December 31, 2025 and December 31, 2024, the related consolidated statements of income, comprehensive income, changes in shareholders’ equity and cash flows for each of the years in the two-year period ended December 31, 2025, and the related notes, and our report dated February 4, 2026 on the effectiveness of internal control over financial reporting as of December 31, 2025 which are incorporated by reference herein.
/s/ KPMG LLP
April 29, 2026
Montreal, Canada