For those just starting you may have realized there are 2 ways of saying goodbye. One is for when you are leaving and the other is when you are staying and your guests/visitors are leaving. If you're ever confused on which is which, here's a little trick I taught myself.
안녕히 가세요 = Is when you're staying, the ending (가세요) gAseyo, visualize the "a" representing the a in the word "stay".
안녕히 계세요 = Is when you're leaving, the ending (계세요) is gyEseyo, visualize the "e" representing the e in the word "leave".
If this is still confusing, just try to remember when to use one and you'll automatically know the other one!