Do you mean way back in evolution, billions of years ago? If so, then animals were reproducing long before they actually knew what they were doing. Very simple animals without brains can reproduce, so it just happens happens automatically.
If you mean how do animals know how to reproduce as the grow up, the usually this is just by instinct. When they become old enough, animals become interested in the opposite sex by instinct.
Comments