The use of the gerund can be one of the most confusing aspects of Latin grammar. However, its use can be distilled into a relatively simple explanation.
What is the gerund?
Gramatically speaking, the gerund is a verbal noun. In practice, this means that the gerund has a verbal '-ing' meaning and is formed from verb stems, but has case endings like a noun. Its neither a true verb, nor a true noun, but has qualities of both.
How do we form the gerund?
It is formed by taking the present stem of the verb and adding -nd- (for 1st, 2nd and most 3rd conjugation verbs) or -iend (for 4th and 3rd conjugation verns with stems in I) and then adding to this the 2nd declension neuter endings.
So, to form the gerund of amare in the accusative we take the present stem ama-, we then add -nd- to make amand-, and finally we add our 2nd declension ending -um to make the gerund amandum. Its simpler than it sounds!
When do we use the gerund?
The use of the gerund varies depending on the case. There are a few easily defined uses that are very easy to spot.
Accusative: The gerund in the accusative is used with ad to denote purpose. So, ad amandum = in order to love.
Genitive: The gerund in the genitive still has its normal 'of' meaning. It is most often seen with noouns such as causa or gratia. So, causa amandi = for the reason of loving.
Dative: The dative use of the gerund is very rare, though it can occasionally denote purpose. Most commonly you will see a dative gerund being used with a verb that takes the dative. For example, credo amando = I have faith in loving.
Ablative: The ablative gerund has all the usual functions of the ablative combined with the 'ing' force of a verb. So, amando = by loving.
That is all there is to it. If you can recognise these few usages you have mastered the vast majority of gerunds that you will see in texts.