"何" is pronounced as "なん" before counter-words like in "何時{なんじ}", "何歳{なんさい}"
etc; or before particles like in "何で", "何とか" etc.

However, it remains to be pronounced as "なに" in some words like "何事{なにごと}",
"何色{なにいろ}", "何者{なにもの}" etc. It can also be pronounced both ways like in "何か".

What is the logic/origin behind this pronunciation difference?
CC BY-SA 3.0
2011-10-19T11:47:25.550
3506
2018-07-16T19:59:46.667
112
question
pronunciation readings
Pronunciation of "何" as "なん" or "なに"
This isn't a complete answer, but there is a strong tendency to shorten to なん
when 何 is followed by a 'n', 'd' or 't' sound.

This obviously doesn't address your first two examples, however.
CC BY-SA 3.0
2011-10-19T18:33:52.457
3511
2011-10-19T18:33:52.457
29
3506
answer
Usually we use "なん" in the following cases :  

  * when the first syllabe of the next word is part of the lines "-た", "-だ" and "-な",
  * as mentioned by Luckman, when we ask a question about a number like in "何時{なんじ}" and "何分{なんぷん}".

In any others cases, we use "なに".
CC BY-SA 3.0
2011-10-20T05:44:42.447
3517
2011-10-21T11:44:28.427
2011-10-21T11:44:28.427
788
3506
answer