You hand in your notice. You do the awkward two-week shuffle. Then, on your last official day, your boss sighs dramatically and hands you the P45.
Is it always on the last day? Legally, yes. Your employer must give it to you when your employment ends. If they don’t, they’re being a bit naughty. Think of it as your financial receipt for “I used to work here.”