んです adds an explanatory nuance — giving or seeking a reason or background.
どうしたんですか。…ちょっと あたまが いたいんです。
What's the matter? … My head hurts a bit.
んです (plain: んだ) attaches to the plain form of a verb/adjective (na-adjective and noun add な: 病気なんです). It frames the sentence as an explanation, a reason, or a request for one.
Use it to ask “why / what's going on” (どうして…んですか) or to explain your situation. Overusing んです on neutral statements can sound pushy.