If a German noun ends in an "e," it's usually feminine, but there are also masculine nouns that end with "e" that require special "n" or "-en" endings in all singular non-nominative cases. To complicate things further, there are also masculine nouns not ending in "e" that require the special endings too!
Basically, the n-declination only occurs with masculine nouns, never with feminine or neuter nouns, and only a small percentage of masculine nouns are weak. Besides the rule of masculine nouns ending with -e, there is no hard and fast rule to classify them — they just have to be learned! It's helpful to know that many are professions, animals, and nationalities. Here are a few examples of weak masculine nouns to remember that you will commonly encounter in everyday usage.
Der Junge is a weak masculine noun, which you know because of the masculine der and the -e ending. Note that the -e ending changes to -en:
Der Zauberer sah zu dem zitternden Jungen hinab.
The sorcerer looked down at the trembling boy.
Caption 80, Märchen, Sagenhaft: Der Zauberlehrling
However, der Nachbar is also a weak masculine noun, despite the -r ending. Note that the -r ending changes to -rn:
Du könntest einfach zum Nachbarn gehen.
You could simply go to the neighbor.
Caption 25, Fine: sucht einen Hammer
Der Student is a very common weak masculine noun that takes the -en ending in non-nominative singular:
Ich habe einen spanischen Studenten eingestellt.
I've hired a Spanish student.
Caption 22, Barbara Schöneberger: Bambi-Verleihung Backstage
Der Herr is a weak masculine noun when it's translated as "lord"
Sofort rannte er zu seinem Herrn.
Immediately, he ran to his lord.
Caption 47, Märchen, Sagenhaft: Der gestiefelte Kater
and in its more common form as the honorific "Mr." or "Mister"
Das war eine Idee von Herrn Singer.
That was an idea of Mister Singer's.
Caption 35, Modedesignerin Nina Hollein: Floria Prinzessin von Hessen
Here are some examples of weak masculine nouns requiring the -n or -en endings in non-nominative singular (all of them have the masculine article der): Architekt, Astronaut, Bär, Bauer, Diplomat, Elefant, Emigrant, Held, Idiot, Kamerad, Kandidat, Kapitalist, Kommunist, Kunde, Löwe, Mensch, Neffe, Pilot, Präsident, Rabe, Russe, Schimpanse, Schwede, and Soziologe. See if you can find some examples of them in context with -n or -en endings on Yabla German. For more reading about this topic, check out the article Tricky Masculine Nouns in German.