The best way to figure out what you need is to go through the questionnaire on the Immigration website (here: www.cic.gc.ca/english/visit/visas.asp). It will cover almost all scenarios, tell you what you need, and point you to how to do it.
I'm assuming from your question that you need a visa to enter Canada, if Canada was your destination. But just in case you want to check, you can find the list of visa-exempt and visa-required countries (here: www.canada.ca/en/immigration-refugees-citizenship/services/visit-canada/entry-requirements-country.html) on the Immigration Department (caution about their website: they are in the midst of migrating from cic.gc.ca domain to canada.ca domain, as well as changing their name from Citizenship and Immigration Canada (CIC) to Immigration, Refugees, and Citizenship Canada (IRCC) - there are an unusual number of dead or wonky links).
To transit through Canada to the US you may need a transit visa even if you are not leaving the airport. It is a similar process to applying for a visa, but there is no fee. You can check your eligibility for a transit visa on the CIC/IRCC website (here: www.canada.ca/en/immigration-refugees-citizenship/services/visit-canada/transit/eligibility.html), find out how to apply online or on paper through the CIC/IRCC website (here: www.canada.ca/en/immigration-refugees-citizenship/services/visit-canada/transit/apply.html), and the website also explains some possible follow-up.
There are Transit Without Visa programs: if you hold a passport from Indonesia, Philippines, Thailand, or possibly Taiwan, and you and your flight meet certain other criteria, you may be exempt as described on the CIC/IRCC website (here: www.canada.ca/en/immigration-refugees-citizenship/services/visit-canada/transit/without-visa/eligibility.html), but it depends on several other variables listed on that page. Similarly if you hold a passport from People's Republic of China (not Hong Kong or Macau), and you and your flight meet certain other criteria, you may also be exempt as described on the CIC/IRCC website (here: www.canada.ca/en/immigration-refugees-citizenship/services/visit-canada/transit/without-visa/china-transit-eligibility.html), but it also depends on several other variables listed on that page.