You would buy ahead of time at National Express.
Looking now (at 2315) the fare for the overnight bus (there is no way you will want to catch that) is £49.20, and for tomorrow afternoon's bus is £54.10
Looking ahead for the next 3 Thursdays it is the same fare, so seems to be consistent. You are paying a £21 airport premium. The bus starts from London Victoria. From Victoria the fare for tomorrow afternoon is £28.20.
If you buy from the machines at Heathrow Bus Station you will pay £2 more than each of the above fares.
The bus leaves from the Central Bus Station at Terminals 2 and 3. It is possible to book from Terminal 5 and catch a coach from T5 to CBS at 1600, but honestly just take a free train between the terminals every few minutes.
You know that I am jittery about you booking the bus in advance then your flight being late and missing the bus.
My own preference would be to catch the bus if the flight is on time, booking there and then. If the flight is late then go into London for a train up to the last at 2110.
If your flight landed after about 1930 (so 4 hours or so late) you aren't going to get the last train from Euston. Even I wouldn't be daft enough to catch the overnight bus after a TA flight. In that case just find a hotel at the airport and travel north next day.
Tonight there is a Premier Inn at the airport for as low as £63. For next Thursday £56.
The Holiday Inn Express at T5, which many people here like, if you walked up there now for tonight is £87.
So neither would break the bank if it came to that. The HIE includes breakfast which is £10 at the PI.
Just examples.