How do you know when to use feminine and masculine when speaking french?

There is no golden rule - you just have to learn all the words and memorise the gender. But, by and large, nouns which end in an -e are feminine and which don't are masculine eg une heure, un jour, une semaine, un mois, un an, une annee