Why a thank-you changes at the end of a visit
The ending gozaimashita often marks an encounter that has come to an end. You might hear it as you leave a shop or finish a guided tour. The distinction is not a rigid rule that requires past tense after every favour: gozaimasu is also appropriate immediately after someone helps you. At the end of an extended visit, the past form is a particularly useful choice.
When an apology expresses appreciation
すみません (sumimasen) can acknowledge the trouble someone has taken for you. Imagine a passenger offering you a seat or a stranger stopping to retrieve something you dropped. The word recognises the inconvenience as well as the kindness. It is not a general replacement for arigatō; combining a brief apology with a direct thank-you can make your intention especially clear.
Let a small gesture do some of the work
A gentle inclination of the head is a comfortable way to accompany spoken gratitude. You need not imitate the deep bows of a formal business setting during an ordinary café visit. Keep the gesture proportionate to the situation. When someone helps you on the street, make space for them to continue on their way rather than extending the exchange unnecessarily.
Appreciation after a Japanese meal
At the end of a meal, ごちそうさまでした (gochisōsama deshita) acknowledges the meal and those who provided it. It is particularly appropriate when someone has cooked for you or treated you to dinner. The expression is tied to eating rather than a general thank-you, which is why it is best learnt alongside, not in place of, ordinary gratitude.