The difference between then is the formalityof speech or the type of use. なぜ is formal and used in the formal conversations and in writing. どうして is more casual then なぜ, and some text books teach as the translation for "why...?". なんで is very casual and colloquial. In everyday conversation, we use どうして and なんで very often.
For "what is the difference between A and B?", I would say: A と B の違い[ちがい]はなんですか。
I hope this helps you.