で vs に
In Japanese sentences both of them mean "in", but they are used in different ways. What's the difference?
In regards to location:
で indicates the location an action takes place. I study at school/in the library. に on the other hand, indicates the location of a person or object. The book is in the bag, the dog is at the park. に can also indicate a destination of movement.
In regards to time:
に is the usual particle used for saying what time something happens, but で can also be used to say what time something finished/will finish.
The verbs come after will determine which one to use. General rule would be,
で: Location for action (the continuous action)
かれは こうえんで あそびます。He plays at the park.
に: Location for existence. (to show state, condition)
わたしは いすに すわります。I sit on the chair.
English "in" is not the only one that shows the location, so it could be in, on, at, under, over or through. It's better to learn the verb and preposition as a set.
～であそびます。～にすわります。～でたべます (to eat)。～にいきます (to go)。～でまっています (waiting)。～にあります (to exist)。
Hope it helps.
To reduce the confusion I only left the "location for existence" for 「に」, the most basic meaning.
「に」 has many different usage. The habitual action I mentioned is only used for certain verbs (to live, reside, go, visit, commute, etc.) とうきょうに すんでいます。(I live in Tokyo.) がっこうに いきます。 (I go to school.) Maybe "habitual action" was not a good choice of words. 「に」is used to show state, condition, situation and circumstances. Whereas 「で」is focusing more on the "doing" (action itself).