You have to give o2 30 days notice to stop it becomming a 30 day rolling contract you need to cancel it.
Adam's said it already really
The number of months in a mobile phone contract is the minimum contract term. After the minimum term is up the contract will continue at the same tariff until you give the operator 30 days notice that you want to cancel.
If you want to keep your number you could ask O2 to change you over to pay as you go. Or if you are coming back to the UK in a matter of months you might want to see if they can transfer you to a very low cost sim only deal. That way when you do come back you will still have your number and you can upgrade to a new contract with a new handset without having to be credit checked. (My sister inlaw was sent by her company to live in Spain for 3 years. She was able to change to a sim only deal costing less than £5 per month. Then when she came back she was able to upgrade. If she handn't of done this she would of had difficulty getting a new contract as she had been out of the UK for so long.)