Essentially, に (ni) is used when going to or through a place, で (de) is used when the action is within the bounds of the place (it can also be used to show the means by which you do something: example below). I'll give a few examples that will hopefully make it clear. The particles are in bold in the English translations, and all hiragana is on the right.
駅に行きます。I go TO the train station. （えきにいきます）
駅で昼ご飯を食べます。I eat lunch AT the train station. （えきでひるごはんをたべます）
公園で遊びました。I played at the park. （こうえんであそびました）
公園に歩きました。I walked through the park. （こうえんにあるきました）
One that is always a bit confusing is 「電車に乗りました」（でんしゃにのりました）which means "I rode the train." It doesn't seem like how you usually use に (ni), but if you just think that you are getting on the train (to ride it), it makes more sense. Otherwise, using に (ni) is pretty straightforward.
I mentioned that you can use で (de) to indicate a tool or means by which you do something, so to contrast with the previous example, you can say 「電車で行きました」（でんしゃでいきました）which means "I went via/by way of the train", or in a less exact translation, "I went by train." Another example:
えんぴつで書きました。I wrote with a pencil / I used a pencil to write. （えんぴつでかきました）
Another particle is を (o), which can be used to indicate a direct object, as well as a place you are leaving.
パンをよく食べます。I often eat bread. （パンをよくたべます）
電車を降りました。I exited the train / I got off of the train. (でんしゃをおりました）
Sometimes に (ni) and を (o) can be used with the same verb, then it helps to know the difference.
部屋に出ました。lit. I appeared in the room / I entered the room. （へやにでました）
部屋を出ました。I exited the room. （へやをでました）
I hope that helps! Let me know if I can clarify anything!