Spanish groups nouns into noun classes using a property called "grammatical gender" (género in Spanish). (The word "gender" comes from the Latin word "genus": the original meaning of "gender" in English was "kind, sort, or genus".)
Spanish assigns most nouns to one of two grammatical classes: these classes are conventionally named masculine and feminine. A very small number of nouns have undecided gender: this means that currently there isn't universal agreement among native speakers regarding whether those words are grammatically masculine or feminine.
Most nouns for people and many nouns for animals specify the biological sex of the person or animal, and a different noun is used for a person or animal of the other sex. Many of these pairs of nouns differ only by the change of a suffix or the addition of a suffix (amig-o/amig-a, perr-o/perr-a, dios/dios-a, león/leon-esa, poet-a/poet-isa), but some pairs are completely different (hombre/mujer, caballo/yegua, toro/vaca). In most cases the noun for something that is perceived as biologically male is grammatically masculine and the noun for something that is perceived as biologically female is grammatically feminine.
For each masculine/feminine noun pair, historically one of the two nouns is the preferred noun for generic reference: that is, the plural form of that word refers to a mixed-sex group, while the singular form of that word refers to a single person or animal whose sex/gender is unknown or not identified. For most pairs the masculine word is used for generic reference; however, there are a few pairs for which the feminine word is used for generic reference. (For more information about social movements regarding grammatical gender vs social gender and biological sex, see the Discussion page for this topic.)
Some nouns for people and animals have the same form for both grammatical genders (el/la artista, el/la dentista, el/la modista, el/la modelo).
Some nouns for people and animals are arbitrarily grammatically masculine or grammatically feminine regardless of the biological sex or social gender of the the person or animal (la persona, la víctima, el testigo, la rana, el sapo, la cabra, la ardilla). In the case of animals, if and when it is necessary to indicate the biological sex one usually uses one of the invariable adjectives "macho" (male) or "hembra" (female): la rana macho, las ardillas macho, el sapo hembra, los sapos hembra.
Nouns for things that do not have a biological sex (for example, table, water, peace, germs, physics) still have grammatical gender, and the gender is arbitrary.
Spanish also makes limited use of a third gender that is conventionally named neuter: however, no Spanish nouns have neuter gender. Rather, neuter gender is used to refer to concepts and statements for which there is no noun and no assignment of grammatical gender.
The grammatical gender of a noun affects all words that modify that noun: all articles and some adjectives have different masculine and feminine forms, and all articles and adjectives that modify a noun must have the same grammatical gender as the noun that they modify.