I thought の when used in questions is for when you’re asking for an explanation or to have a curious tone, but んだ is also for explanation and I’ve seen both used to end questions so what are the differences between them?
For yes-no type questions:
Sentence 1 is very common, and sounds friendly and neutral (i.e., you have no prior assumption). Syntactically, sentence 2 may not be a question, but with a question mark, it sounds more like a confirmation with a surprised and/or accusatory tone ("So...you ate it, is that right?").
For wh-type questions (どこ, 何, etc):
Sentence 3 is a simple, gender-neutral, colloquial question. Sentence 4 sounds masculine (or sometimes militaristic), blunt and often oppressing. You usually don't have to say a sentence like 4 even to your family.