I'm new to German and I get a bit confused about when it's "dem" or "im" or "den" rather than "in der" or "in dem" and so on.
In many languages, prepositions and articles are sometimes contracted.
Contractions that may occur in informal speech:
As for choosing between different cases:
This corresponds to the knowledge of deciding if the correct English sentence is "I touch you." or "I touch to you." and very often, the construction with "to" corresponds to dative in German and without it to accusative in German. In the light of the next phrase it can be more helpful to think of the action being done "for" someone when the dative is used.
For prepositions again, you should learn what case they demand, but an important rule is: If the meaning is where something is, then the object has to take the dative, if the meaning is where it moves to, then the object has to take the accusative. Note that this deviates from the correspondence with "to" in the previous paragraph.
It would be good to ask a more specific question if you want to know more.
In informal speech uncontracted expressions like
In written German, use only the contractions enlisted by Phira.
If you are in doubt, I would advise not to use a contraction as they tend to sound a little "uncouth" if overused.
Und noch mehr:
Aber die Frage war "when would one ..." :
Praktisch immer, ausser in sehr förmlichen Texten, wie in Gesetzestexten oder behördlichen Schreiben.