Grammatical gender is phenomenon that occurs in some languages, where nouns are categorised into different groups. These groups may take on different morphology. For example, in Italian, words that end in -o are said to be "masculine" and are pluralised by changing to the -o to -i (gatto "cat" > gatti "cats") and words that end in -a are "feminine" and are pluralised by changing the -a to -e (tavola "table" > tavole "tables").
Alternatively, different genders may have to be used with different forms of other words. For instance, in Italian, the word for "the" has a different form for masculine singular, masculine plural, feminine singular and feminine plural: il, i, la, and le, respectively.
The term "gender" is generally agreed to be fairly misleading, as in 99% of cases the gender of a noun has nothing to do with any apparent biological sex, or gender identity. The term stems from European languages, where words for male things tend to be of once category, thus earning the label "masculine, and words related to female things are of another category, earning the label "feminine". The term "noun class" is often used for languages who have multiple noun categories that bear no relationship to notions of gender at all.
The function of genders and noun classes is to add extra information to the sentence so that listeners can better guess what is being said in poor hearing conditions. To take the Italian example, if a speaker says "i gatti" (the cats) and the hearer doesn't hear the plural end of the word well, he can still deduce that it was "gatti" based on the plural definite article "i", and that it was not some other feminine word that might begin with "gat-".