A fully automated procedure for detecting and centering protein crystals in the X-ray beam of a macromolecular crystallography beamline has been developed. A cryo-loop centering routine that analyzes video images with an edge detection algorithm is first used to determine the dimensions of the loop holding the sample; then low-dose X-rays are used to record diffraction images in a grid over the edge and face plane of the loop. A three-dimensional profile of the crystal based on the number of diffraction spots in each image is constructed. The derived center of mass is then used to align the crystal to the X-ray beam. Typical samples can be accurately aligned in approximately 2-3 min. Because the procedure is based on the number of ;good' spots as determined by the program Spotfinder, the best diffracting part of the crystal is aligned to the X-ray beam.