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 -ción, -sión, -dad, -edad, -idad, -tad, -grafía, -itud, -tumbre, and -dumbre are feminine.
We also know some exceptions to the -a rule: many nouns ending in -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"(short for "fotografía) and "mano" (hand) end in -o 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 city." translates to "El autobús viaja en la ciudad capital."
So, how do we know that "autobús" is masculine and "capital" is feminine?