If you want to own the software developed for you, you must have an explicit agreement in writing to own the software - otherwise, the developer retains the ownership.
When you hire an external software developer, you should receive a software development agreement from the developer. We can review the agreement to ensure it protects your legal position. If the developer does not provide you with an agreement, we can draft one for you.
Usually a software development agreement provided by a software developer will only license you the right to use and sell the software. A licence means the developer will retain rights to the code. That licence can be revoked. If you want to have ownership rights, you need to renegotiate with the developer for an assignment clause. This needs to happen before you sign the agreement.
Even if your developer has already developed the software, you can still use an IP assignment agreement at to assign the code to you. However, in general, you will have much more leverage to ask for the assignment before you hand over your money initially.
A software developer is unlikely to want to assign any precedent code (from past jobs) used in your software development over to you. The software developer will reuse the precedent code on other jobs. They will only want to assign your unique code. Where free open source software has been used in your software, the developer does not have the ownership rights to assign it to you.
If you employ a software developer, the employment agreement should include a clause which ensures all intellectual property (IP) created by the developer in the course of their employment automatically assigns to you. This assignment will give you ownership of the IP, which will include any software the developer creates while employed by you.