1. Distinguish prepositions and conjunctions according to their respective characteristics:
A preposition is followed by a noun or pronoun or gerund, and
A conjunction is followed by a sentence. So we can distinguish before and after according to whether the components behind before and after are sentences or not.
For example, before playing basketball, he finished playing at home. Here before is followed by the gerund phrase playing basketball. It is not a sentence, so it is a preposition here, which means "after" according to the context.
2. Distinguish according to the meaning.
According to the Oxford Dictionary, before has the meaning of "before" when used as a conjunction and a preposition, but other meaning is unique to prepositions/conjunctions.
When after is used as a preposition and conjunction, it also means "after (in time)", but when after is used as a conjunction, it only means this. When after is used as a preposition, other meanings are unique.