In the wizarding world, the Ministry of Magic sets the legal age for performing magic outside school at 11 years old—coinciding with the typical Hogwarts acceptance age. Before that, children are deemed unable to control their magical abilities, making unsanctioned magic generally illegal.
Once a witch or wizard turns 11, they may perform magic outside school provided they follow Ministry regulations—though the Trace charm still monitors underage magic until age 17.
The Trace is imperfect: household magic by adult witches and wizards masks underage spells, leading to inconsistent enforcement. The Ministry often relies on self-reporting or obvious violations.
Bottom line: Legal age is 11, but accidental or defensive magic by younger children is pragmatically overlooked.