Strangely enough, it is easier to keep a phone number when transferring from one network to another than it is from changing from one tariff to another on the same network. This is because the number porting procedure was introduced by Ofcom to guarantee phone users the right to keep a phone number when moving from one provider to another, but no regulations were ever introduced for changing phones with the same company.
While it is a much simpler process to transfer your number when moving to a new network, it is not entirely impossible when staying with the same provider. In order to retain your phone number while moving to a new tariff on the same network you will need to negotiate a contract upgrade with that network. Because of this you may not be able to keep your old number when moving to a new contract purchased through a third-party retailer.
Some of these retailers may be able to arrange this for you if you ask them but be wary that they may offer things they cannot deliver in order to secure a sale.
If you cannot negotiate the new tariff or phone that you would ideally like directly with your current network then there is one other method that you could use to keep your existing number, although it is a somewhat convoluted process. You can transfer your number over to a separate PAYG SIM on a different network, and then transfer it back over to your new contract.
The process is more straightforward when moving from a Pay As You Go (PAYG) phone to a contract phone with the same network as you can still retain your number while moving to a new tariff/phone. In order to do this you may need to follow the standard number porting procedure by requesting a PAC code, particularly if ordering through a third-party retailer. When ordering a new contract phone directly from your network you will not usually need to go through this process, just inform them that you wish to keep your phone number from your existing PAYG SIM.