You can keep the number usually provided the area code and the first two digits of the number are the same. I believe the area code is just that, an area code and the first two digits of the number denote which exchange you are on. Having the first five digits (area code) the same does not guarantee still being on the same exchange. To set up forwarding you have to pay "line" rental still even though it's not an actual line.
If you want to avoid such a situation in the future, why not get an 0845 number? You can then point the 0845 number to your new number. 0845 numbers are usually free unless you want an easy to remember one. There are many providers of such so-called "virtual" numbers on the web.