Simple, non-derived words have to be learned together with their inherent gender. They often have just one syllable or a complex one followed by a weak schwa syllable (or syllabic sonorant) and occur quite frequently.
Derivation rules
The rightmost part of a compound always determines its gender and its noun class (for inflection).
This rightmost part may be a derivational morpheme that does not exist isolated and may not be productive any more.
The list of these, which includes native and adopted foreign ones, is finite and should be learned by examples early on.
Each suffix only works with one kind of stem (noun, verb, adjective) and there are ones for every relation, but some look alike at first.
Many of these can be chained [see diagram], but nominal ones only in masc.-fem.-neut. order, and each one has to obey the previous rule; combinations of three or more derivational suffixes are rather rare, but plural and case suffix (GenSg or DatPl) may follow.
Some affixes look and sound ambiguous, e.g. ending -er appears in non-productive indoeuropean kin marker {+ter|+der} as in Schwester, Bruder and in strong masculine adjectives used as nouns like Erster, Grüner and in agent markers {+er|+ner|+ler} (which has non-native variants {+er|+eur|+ör|+or|+ier|…} and may be followed by female marker {+in}) and in certain umlaut plurals like Kind+er, Wäld+er and in certain non-masculine high-frequency words like die Butter, das Wetter.
General rules
There are five regular nominal plural forms in German: E, N, R, S and ∅. The final, empty allomorph is often really one of the others with the stem already ending that way. The consonants are often either syllabic or succeed a schwa that may or may not be present in NomSg. IIRC, umlauted plural stems only occur for E and R (and their ∅ variants), hence Ë and R̈. You can construct noun classes from that which somewhat correlate with gender. A lot of words are regular, but not every ending is a definite indicator for a noun class. Unless noted otherwise, the following regular native neuter words are ∅, native masculines and foreign neuters are E, foreign masculine and all feminine words are N.
Old animate male words may end in +hold, +bold, +ling, +ing and +rich, most of which are rather uncommon. Few native masculine have an ending of +ig or +ich that otherwise indicates an adjective. Singular nouns ending in +en are male with empty plural like most similar words ending in {+er, +ner, +ler} or el. Of the latter ones, -er and -el also appear with different gender. The agent morpheme {er} has the French variant {+éur, +ör} with same plural, whereas foreign alternative íer is rare S and +or is N like the Romance +ánd, +ánt, +ént, +ist, +ism-us and Greek +e, +∅.
Unambiguously native feminine suffixes are +heit, +keit, +schaft, +ung and with slightly less certainty {+ei, +lei, +rei} and, of course, animate +in that often follows +er. Foreign feminine suffixes are as numerous as regular, +énz, +ánz, +íe, +ik, +ík, +ítis, +sis, +is, +túr, úr, +atión, +ión, +itä́t, +ä́t. Just e, áge, áde, … requires more attention.
All diminutives are neuter, the usual native endings being dialectal or poetic {⸚lein, ⸚le, ⸚li, ⸚[e]l} and standard ⸚chen. Verbal infinitives with +en (otherwise a masculine indicator) used as nouns are also neuter as are most derivates with Ge+ prefix and optional +e suffix. (Action stems without obvious suffix are usually masculine, however.)
Another neuter derivational morpheme ist productive +tum with R̈ and sometimes E plural. Foreign neuter suffixes are mostly regular with +át, +étt, +ín, +on, +ón and Latin +mént, whereas French and English +mént has S plural and +ium, +um often have no plural at all or retain their foreign one.
Irregularly masculine nouns ending in +e (also foreign ones) and feminine ones ending in (seemingly masculine) +er or +el also have N plural, whereas neuter words with the same endings or +en have empty plural as usual.