I assume that you are asking about the legal doctrine of self-defense. Under this doctrine, a person is allowed to use force (even up to force that ends up killing someone else) in defending themselves or other people around them (or their property). A person who harms or kills someone in reasonable self-defense cannot be charged with a crime.
There are limits on this right, however. Basically, the person acting in self-defense must generally have a reasonable cause to fear that they (or the people they are defending) are going to be seriously harmed by another person. In other words, you cannot shoot someone because they look like the kind of person who might murder you. Similarly, you cannot shoot someone who you see picking your cell phone up off your front porch and walking away. But you can shoot them if they are coming towards you holding a knife in a threatening way.
Please be aware that different jurisdictions have different laws on this and that this explanation is simply a general discussion of the idea.