I have progressed pretty far in Japanese, but when I construct Japanese sentences, I still get these two particles mixed up. For example, when talking about being inside something, I don't know when ...

The title should be pretty self-explanatory. What meanings does each convey? And in what kinds of circumstances would one be used instead of the other?
For example, what are the differences between ...

Following the current trend of pitting the particles に and で against each other, here is another question that does the same but from another type of usage and perspective.
When we want to say "do X ...