The process begins with the creation of a training set, where emails are manually labeled as spam or ham. The algorithm then analyzes the frequency of certain words or phrases in these emails. When a new email arrives, the filter calculates the probabilities of it being spam or ham based on the words it contains. These probabilities are then combined to produce a final score, which determines the classification of the email.