We know that in Spanish and many other languages, nouns ending in -o are mostly masculine and nouns ending in -a are mostly feminine.
We also know that in Spanish, nouns ending in -ión, -ción, -sión, -dad, -edad, -idad, -tad, -grafía, -tud, -tumbre, and -dumbre are feminine.
We also know some exceptions to the -a rule: many nouns ending in -ma, -ema, -grama, and -oma are masculine.
There are other words ending in -a like "día" (day) and "mapa" (map) which are masculine. The words "foto"(photo) (short for "fotografía) and "mano" (hand) end in -o, but are feminine. There are other words ending in -o, which are short forms of feminine nouns, and are still feminine.
But, how do we know the gender of nouns with arbitrary endings?
"The bus travels in the capital." translates to "El autobús viaja en la capital."
So, how do we know that "autobús" is masculine and "capital" is feminine?