ESTA is an automated travel authorization system for foreign nationals under the Visa Waiver Program. Citizens of any of the 38 visa waiver countries may apply for ESTA.
The U.S. Customs and Border Protection (CBP) advice to always apply as soon as you know the date of your trip to the United States.
However, most applicants will receive a response almost immediately, as long as all eligibility requirements are met.
Despite that, it is advised against making a last-moment application. The standard timeframe between your flight and ESTA application should be at least 72 hours. Within this period most applicants will know whether or not they received an ESTA approval.
In rare cases, the application status may be pending longer, which means CBP is carrying out further investigation. It is advised to wait a couple of hours before seeking a status confirmation.