Ejes has got it right. In my little hamlet, there's actually a stated ordinance prohibiting it without permission from the police department. Two minutes over in the next burg, there's nothing stopping you whatsoever from doing it in your own backyard.*
In some areas, you can only do it in specially designated ranges--marked off with a berm, safety fencing, and so on.
In other areas, you can do it if you're discrete about it, and like Ejes said, know what's behind you, to the sides, behind your target, and over your head.
If you're within driving distance to an unincorporated area, my third paragraph would likely apply.
*Actually, the ordinance would let me do it in my backyard, as its language refers to "public spaces," but there's always reckless endangerment if I don't use a backstop of some sort! :foot: