Start here how to patent
You patent in all the countries that you want to stop someone building OR selling your invention, but since the only important country that allows software patents is the USA you can start there.
Now the good news - you almost certainly need professional help to write the patent ( figure on $20-50K) then a lawyer to file it ($2-5k) and then you have to pay the filing and search fees ($5-15k)
Then repeat this for each new country, with the addition of translation fees.
Then IF the patent is granted you get to pay to defend it in court against all the lawyers from Microsoft/IBM/Oracle etc.
If you merely want to show that you had the idea and stop someone else filing a patent on it then getting it published in a paper journal would be good.
Websites describing it are a little more difficult. You need the site to still be around in 10years when it comes to court you need an organisation that the court has some trust in (like a commercial journal or national user group).