The meaning of these words is actually very simple to explain in English.
A senpai 先輩 is, usually, the older guy, or girl, in an organization. The senior. The one who was there before you joined the place. It so often happens that the people who were there before you are also people older than you.
A kouhai 後輩 is, well, the antonym of senpai. A kouhai is the guy calling people senpai. For every senpai in the world there is a kouhai, and vice-versa. After all you can only be somewhere relatively longer than someone else if there is this someone else relatively newer than you are in there.
Often in anime we see characters calling other characters senpai.
Like, say there's this guy, Tanaka 田中, and people usually call him just Tanaka-san 田中さん, and this girl, Emiko 恵美子 calls him Tanaka-kun 田中くん, but then he goes to the second year and his junior from first year, Osawa 大沢, starts calling him Tanaka-senpai 田中先輩.
So, now, Tanaka-senpai, whose kouhai is Osawa, just calls Osawa... Osawa. Never, ever calling him Osawa-kouhai. Why is this?
The senpai-kouhai 先輩後輩 system is a custom and culture of Japan which basically means a hierarchy where seniors are at the top and juniors don't matter.
This works the same way as for brothers. An younger brother could call Tanaka Tanaka-oniisan because he is the older brother, but an older brother wouldn't call Tanaka Tanaka-otouto, because his social standing as the lesser brother doesn't warrant the use of this honorific.
Senpai is (Not) Older
A senpai is not someone who is older than someone else. In schools, where most of the senpai-calling anime happens, you usually start at a certain age which mostly everyone else starts at, too. The longer you're at school, the older you are relative to someone who just started school.
This can give the impression that a senpai is the older guy, and the kouhai is the younger one in a senpai-kouhai relationship. But this isn't true.
Senpai is (Not) School
Another misconception is that senpai and kouhai are only used in schools. A senpai isn't the guy who's in second year when you are at first year, and a kouhai isn't the opposite either.
In a company, for example, a senpai is the guy who got a job in there before you did. He will be your senpai forever and you'll be his kouhai forever too. You can't fight the time conundrum!
Even the staff of a school have senpai-kouhai relationships. A teacher can be a senpai of another teacher if he started working earlier.
Senpai is (Not) Advanced
Likewise, a senpai is not someone who has achieved more than you did, or someone who is a manager while you're a managed. The senpai-kouhai system is a social hierarchy of its own and is parallel to other social hierarchies.
What is Senpai?
After all these things that are not senpai comes the question, just what is a senpai? What is it for, what's the point of labelling people like that? I mean, it's not even restricted to schools, or anything, it just the guy who's there first.
I mean, literally, the kanji 先 and 後 in senpai 先輩 and kouhai 後輩 have the meaning of "before" and "later".Have you ever heard these words in anime: saki 先 and ato 後? Same kanji! Same meaning!
The truth is, when you arrive somewhere, wherever it is, you don't know anything about anything so you need to ask someone who's already there for help. Anyone who can help with you is your senpai.
A senpai 先輩 is a guy who helps their kouhai 後輩 figuring out what to do where they are. Job-related senpai will often teach their kouhai the ropes of the job, intermediate with bosses whom they know better, etc.
Meanwhile, the school senpai are also often leading and organizing club-related activities of which they are part of and so on, so they can be relied upon for that.
Neither Senpai nor Kouhai
Someone who is not a senpai 先輩 and isn't a kouhai 後輩 either, but is at the same place, is called a douhai 同輩.
Except it isn't, really, because what's the point of calling someone that?
The word douhai is written with the same kanji as the word onaji 同じ, meaning "same". More often, in anime, in school anime, we see the word doukyuusei 同級生 instead of douhai.
A doukyuusei is someone, sei 生, who is at the same "level," kyuu 級, as you are. Meaning the same school year, school level.