German prepositions are divided into three groups based on which case they require. The first group always takes the Akkusativ, and these prepositions are durch (through), für (for), gegen (against), ohne (without), um (around), bis (until), and entlang (along). For example, you would say Das Geschenk ist für meine Mutter (The gift is for my mother), where für triggers the Akkusativ form meine Mutter. Other examples include Wir gehen durch den Park (We walk through the park), where der Park becomes den Park in the Akkusativ, and Ohne dich kann ich nicht leben (Without you I cannot live).
The second group always takes the Dativ. These prepositions are aus (from or out of), bei (at or near), mit (with), nach (after or to), seit (since or for), von (from or of), zu (to), and gegenüber (across from). Because prepositions and articles frequently contract in spoken German, you will often encounter forms like zum, zur, vom, and beim. The verb fahren uses mit, so Ich fahre mit dem Bus means I ride the bus, where der Bus becomes dem Bus in the Dativ. The preposition aus is used for origin, as in Ich komme aus der Türkei (I come from Turkey), where die Türkei becomes der Türkei. The preposition seit is used for duration, as in Seit einem Jahr lerne ich Deutsch (I have been learning German for a year), where ein Jahr becomes einem Jahr in the Dativ.
The third group, called Wechselpräpositionen (two-way prepositions), can take either the Akkusativ or the Dativ depending on meaning. These are in, an, auf, über, unter, vor, hinter, neben, and zwischen. When the answer to the question Wohin? (where to?) involves motion or direction, use the Akkusativ. When the answer to the question Wo? (where?) describes a static location, use the Dativ. For example, Ich gehe in die Schule means I am going into the school (motion, hence in + Akkusativ), while Ich bin in der Schule means I am in the school (location, hence in + Dativ). Similarly, Die Katze springt auf den Tisch means The cat jumps onto the table (motion, Akkusativ), and Die Katze sitzt auf dem Tisch means The cat is sitting on the table (location, Dativ). The choice of case depends entirely on whether something is moving toward a place or simply being at a place.