I did this in my first job, giving two months of notice because it was the right thing to do for my colleagues and the company since it'd allow transition time and continuity.
Then I was let go immediately. Which was an unexpected hit, though luckily the new company let me move my start date up. This was a tech company with around one hundred employees, and I was in good standing (my then manager later recruited me for a position at a different company).
The best approach is to always give two weeks formal notice on a Friday morning, with the expectation that there's a chance you'll not be coming back on Monday. Best to do all the transition preparation work before that moment. If I've got a manager that I trust, I let them know with a bit more informal advance notice.
Then I was let go immediately. Which was an unexpected hit, though luckily the new company let me move my start date up. This was a tech company with around one hundred employees, and I was in good standing (my then manager later recruited me for a position at a different company).
The best approach is to always give two weeks formal notice on a Friday morning, with the expectation that there's a chance you'll not be coming back on Monday. Best to do all the transition preparation work before that moment. If I've got a manager that I trust, I let them know with a bit more informal advance notice.