Will you only gain weight if you go over 3500cal?

I don’t understand how weight gain happens....so do you only gain weight if you go over 3500 calories or? Lol