The ESTA Visa is valid for a period of two years. However, this does not mean that you can travel to the U.S. and remain there for the entire two year period. The visa restricts stays for visitors to the country to 90 days per visit. This means that a visitor is required to leave the country before their visit exceeds 90 days.
Should you want or need to stay in the country for a period exceeding 90 days, it is necessary to apply for a B-2 Tourist Visa which allows for stays of up to 6 months. It is not necessary to apply for an ESTA visa if you have already been approved for a B-2 visa.
The ESTA visa does allow for multiple entries into the U.S. which means you can return to the country even if you have stayed the maximum amount of 90 days. While there is no defined amount of time that you will need to spend outside of the country before returning, a reasonable amount of time should pass before you return.
It is up to the customs and border official at your port of entry to decide whether a reasonable amount of time has passed. Leaving the country and returning the next day will not be acceptable. Other factors may also be taken into account upon your return such as whether you returned to your home country or only spent a few nights in a bordering country before returning. Generally, a few weeks in your country of origin or home country should allow for re-entry into the United States.
The reason for this assessment upon returning is to determine whether a person has been or is intending to work in the United States upon their return. It is not permitted to work in the U.S. on an ESTA visa.