There are four main elements to the formation of a contract:
Offer
At its core, every contract must involve an offer to do (or not do) something. This can take many forms, such as an offer to sell a car, or to provide bartending services for an event. But generally speaking, every agreement involves some form of an offer of an exchange of value.
Acceptance
The party (or parties) to whom the offer is made must accept the offer. Once a contractual offer has been accepted then the offer may not be withdrawn.
Consideration
In order for the accepted offer to be binding, there must be some form of value exchanged. For example, if someone agrees to pay $500 for a car, then the $500 being paid to the seller is the consideration for the car. It is a form of value being exchanged for the car being offered.
Intent
The final component of a binding contract is that all parties must intend to enter into a binding contract on the agreed-upon terms. This can be demonstrated in a variety of ways, including by having the parties sign the final version of an agreement. The purpose is to show that the parties reached terms that they agreed upon and accepted those terms as a contract.
A contract may be formed whenever these four basic elements are present. Once a contract is formed then it can be legally binding, and any party to the contract may try to enforce it against the other party(ies). However, if any of the four elements are missing then there may not be an agreement that the parties can rely on.
It is also important to keep in mind that not all contracts need to be in writing, and so a contract may be formed verbally.