At 18 days [when the mother is only four days late for her first menstrual period], and by 21 days it is pumping, through a closed circulatory system, blood whose type is different from that of the mother. J.M. Tanner, G. R. Taylor, and the Editors of Time-Life Books, Growth, New York: Life Science Library, 1965, p.
With an ultrasound, at about 3 or 4 weeks. With the device the doctor uses in the room, at about 9 weeks. I don't know for the things you buy at the store.
I am going to disagree with this last answer. With a vaginal ultra sound a heartbeat can be detected as early as 6 weeks gestation but more commonly by 7-8 weeks gestation. Of course she could be right and we are just counting the weeks differently.
With my first child my Dr. could hear my son's heart beat at 7 weeks with out a ultra sound and now being pregnant with my second child and having the experience in a medical setting working in a OB practice I have heard my baby's heart beat at 5 weeks and 3 days.
Mayo Clinic says the heart begins to beat at 5 weeks and may be seen with an ultrasound.
But note that the Mayo Clinic, numbers the weeks according to the start of the last period, so that conception is regarded as happening in week 2; thus the heartbeat begins during the 4th week after conception.)