It depends on the last vowel sound of verb or adjective stem
-았- is used after the vowel ‘ㅏ’, ‘ㅑ’, ‘ㅗ’, ‘ㅘ’
-었- is used after the vowel ‘ㅓ’, ‘ㅕ’, ‘ㅜ’, ‘ㅡ’, ‘ㅣ’, ‘ㅐ’, ‘ㅔ’, ‘ㅙ’, ‘ㅚ’, ‘ㅟ’, ‘ㅢ’
-였- is used after the verb or adjective of '하다'
ex)
가다(go)
verb stem is 가
The last vowel of 가 is ㅏ
가 + 았습니다 => 가았습니다(omitted duplicated ㅏ) => 갔습니다
울다(cry)
verb stem is 울
The last vowel of 울 is ㅜ
울 + 었습니다 => 울었습니다.
잡다(take)
verb stem is 잡
The last vowel of 잡 is ㅏ
잡 + 았습니다 => 잡았습니다
오다(come)
verb stem is 오
The last vowel of 오 is ㅗ
오 + 았습니다 => 오았습니다(contracted ㅗ and ㅏ to ㅘ) => 왔습니다
공부하다(study)
verb stem is 공부하
공부하 + 였습니다 => 공부하였습니다(contracted ㅏ and ㅕ to ㅐ) => 공부했습니다
There are some irregular verb or adjective
슬프다(sad) ㅡ irregular
verb stem is 슬프
The last vowel of 슬프 is ㅡ
슬프 + 었습니다 => 슬프었습니다(omitted ㅡ ) => 슬펐습니다
돕다(help) ㅂ irregular
verb stem is 돕
The last vowel of 돕 is ㅗ
돕 + 았습니다 => 돕았습니다(changed ㅂ to ㅗ ) => 도왔습니다
부르다(call) 르 irregular
verb stem is 부르
The last vowel of 부르 is ㅡ
부르 + 었습니다 => 부르었습니다(omitted ㅡ and doubled ㄹ ) => 불렀습니다