“в” + noun in prepositional case means location (“in”), while “в” + noun in accusative case means direction (“to”). Note that for most sentences only one of those usages makes sense, the other would use another preposition.
“Кит плывет в океан (acc.)” — “A whale is swimming towards the ocean” (from a sea maybe)
“Кит плывет в океане (prep.)” — “A whale is swimming in the ocean” (NB: “по океану” would be a bit more natural)
As for what applies to what:
Иван Иванович идёт на работу в гараж. (Implies he has a job at the garage.)
Иван Иванович идёт (куда?) {на работу} (куда?) {в гараж}.
Иван Иванович идёт в гараж на работу. (equivalent)
while:
Иван Иванович идет поработать в гараже. (He goes with the purpose of working in the garage.)
Иван Иванович идет (что делать?) {поработать (где?) {в гараже}}.
Иван Иванович идет в гараже поработать. (Almost equivalent, but sounds a bit weird. Could occur if someone wanted to emphasize “в гараже” in speech.)
Because “на работу” is such a common phrase, the word “работу” does not really function as a standalone word. While if you break the phrase up, or use a synonym, you can attach other words to that “работа”.
Иван Иванович едет на работу в центр города.
Иван Иванович едет в центр города на работу.
Иван Иванович едет на свою работу в центре города.
Иван Иванович едет (куда?) {на свою работу (где она находится?) {в центре города}}.
в/на + accusative case
, which means "to (some destination)".