Phase retrieval is an image-based wavefront sensing process, used to recover phase information from defocused stellar images. Phase retrieval has proven to be useful for diagnosis of optical aberrations in space telescopes, calibration of adaptive optics systems, and is intended for use in aligning and phasing the James Webb Space Telescope. This paper describes a robust and accurate phase retrieval algorithm for wavefront sensing, which has been successfully demonstrated on a variety of testbeds and telescopes. Key features, such as image preprocessing, diversity adaptation, and prior phase nulling, are described and compared to other methods. Results demonstrate high accuracy and high dynamic range wavefront sensing.