It’s a good question that I had to answer and understand myself a few years ago so I learned about the subject.
Affairs begin with a blossoming friendship formed at work or a hobby group or friend group etc.. This new friendship is deemed initially in the minds of the two people involved to be innocent. They reason that they’re good people who, despite being attracted to each other, would not cross lines into an affair. Neither of the people involved were necessarily previously aware of being unhappy in their existing relationship/marriage.
As the new friendship grows, subtle lines gradually begin to be crossed. They start to confide in one another, for example. I imagine it a bit like a scale slowly tipping in favour of the affair partner, as the affair friendship/relationship develops, the brain is flooded with ‘feel good’ chemicals generated by the excitement of the new friendship and the attention and flattery that is being received. So the scale slowly tips in favour of the affair partner.
A consequence of this is that the existing relationship/marriage begins to look far less appealing compared to the new, exciting and flourishing friendship.
The new friendship eventually becomes physical. Something called cognitive dissonance occurs (human beings have a need to justify their behaviour; ‘I’m a good person and I wouldn’t need to have an affair if I was happy in my current relationship; my current relationship is lacking.’ This is obviously in some cases a fact, but from what I learned, it isn’t always a factor and previously happy or content people can slide into affairs. This is why for some, choosing between their committed relationship and the new one is a dilemma and they vacillate).
Once the affair is in full, physical and emotional swing, the existing relationship/marriage is viewed extremely negatively in comparison to the affair partner relationship. The spouse/existing partner becomes the ‘bad person’ and that relationship highly problematic. It pales in comparison to the new one. This is due to cognitive dissonance, as I understand it.
That is my understanding of how affairs happen. Understanding that people gradually slip into these situations was very helpful to me at one point in my life. Understanding that it wasn’t necessarily something that I had done that had caused this to happen, helped.
There are loads of great educational videos on YouTube about it. I found Affair Recovery and Marriage Helper helped me understand how and why this happens.