It is a Torah commandment to teach Torah to children. Thus we read: “Teach them to your children” (Devarim 11:19). The primary objective of this teaching is to ensure that the children observe all the Torah’s instructions: “Study them and be careful to do them” (Devarim 5:1). Therefore, the Sages stated that alongside the mitzva to teach children Torah is the obligation to educate them toward mitzva observance. For how can they be taught the mitzvot without getting used to keeping them in practice? Thus, there is a Torah commandment both to teach children Torah and to accustom them to keeping the mitzvot in general. Nevertheless, the actual observance of specific mitzvot by the child is a rabbinic obligation.
A child should be educated to keep the positive commandments from the time that he can understand what the mitzva involves, and can properly observe it. Thus, the appropriate age for each mitzva varies in accordance with its complexity and the difficulty of its observance. For example, a boy should be educated about tzitzit once he knows how to put them on, can make sure that there are two sets of strings in back and two in front, and can recite the berakha. However, since one may only put on tefilin if he is able to maintain a clean body and utter concentration, a boy should only be educated about this mitzva shortly before his bar mitzva (Sukka 42a; MB 343:3).
The age at which we begin to educate children about mitzvot is about six or seven because that is when children start to study Torah in earnest and thus can begin to keep most mitzvot properly. This applies to berakhot and prayers as well. The age of ĥinukh is six or seven, as that is when most children can begin to do them properly. Nevertheless, we begin habituating them to recite berakhot and prayers from around the age of three, just as they start learning Torah at that age (BB 21a; Sukka 42a; SA YD 245:5).
The same principle applies to kiddush and havdala; from the age of three we begin to encourage the children come and listen. When the child understands the idea of Shabbat and can listen properly to kiddush and havdala, we make sure that he does so. If he is not present when kiddush or havdala is made, he should recite it himself.