It differs from state to state. General rule of thumb is if you are in fear of you life or serious bodily injury, you may shoot. However, deadly force is the last option. In most states you must retreat if available without exposing yourself to harm. On your own property is usually an exception; some states have a "castle doctrine" clause. You don't have to retreat; if somone is in your house and seems to be a threat, you are justified to end the threat.
This is not legal advice. All this information is from my own research.
www.packing.org
The message board is a good starting point for more information if you are interested.