These are what are called innate behaviors, animals know them from the time of birth roughly speaking. Another great example is the fact that calves can stand and walk within hours of being born.
We have no idea how these behaviors are encoded genetically or neurologically and this is an active area of research.
Latest Answers