Nani (なに) means “what”. Before です and a few other sounds it changes to なん, as in なんですか (“what is it?”).
The hero freezes. The camera zooms in. なに?! It is one of the first Japanese words anime fans learn — and yes, it really is just the word for “what”.
What it actually means
なに is the question word “what”. In a full sentence it sits where the answer will go, and the sentence ends in か.
なに or なん?
Same word, same kanji (何), two sounds. It becomes なん before です, and before the sounds t, d and n, because that is easier to say: なんですか, なんの ほん (“what kind of book”), なんと いいますか (“what do you call it?”). It is also なん with counters: なんじ (what time), なんにん (how many people). And one to learn as it is: なんようび (what day of the week). Before を and が it stays なに: なにを, なにが.

それは なんですか。
What's that?

おべんとうです。
It's a packed lunch.
The anime なに?!
Shouted alone, なに?! is shock or disbelief: “What?!” Real people do say it — to friends, when something surprising happens. But a bare なに? in answer to someone who called your name sounds blunt, like “What?” in English. With people you don't know well, answer はい? instead. Even the polite なんですか can sound cold as a reply to your own name.
Can you use it?
Every day. Asking これは なんですか is one of the most useful things a beginner can do in Japan: point, ask, and you get a new word each time. Keep the dramatic なに?! for friends and for watching anime.