In a nutshell:
If the person has more experience or looks like they have more experience (Whether it be in life or in whatever field they're in) you call them senpai.
Likewise, if someone has less experience or are less knowledgeable in something, you refer to them as your kouhai.
It's not always about age, although usually the older you are, the more knowledgeable you'll be (Hopefully lol). However, if you're an old man who just entered a company and the guy training you happens to be much younger, you (as an old man) should refer to the young guy as senpai, since he has more experience/knowledge than you. It might be an embarrassing situation, but that's life