なんで + [sentence]? なんで?
なんで is "why" in casual speech. It goes at the front of the question, and the question usually ends in の, or んですか when polite: you are asking for the story behind something.
All three mean "why", and the difference is register. なんで is the most casual and belongs to conversation; to a teacher or a boss it can sound blunt. どうして works in casual and polite speech alike. なぜ is the formal one, and the usual one in writing.
Said alone, or in an exclamation, なんで carries surprise or frustration rather than a real question.
なんで can also be 何 + で, "with what", "by what". Context decides which one is meant. To ask only about the means, use どうやって.