This paper describes a simple technique to design compact air core magnets for magnetic resonance imaging (MRI). The optimum geometry is obtained by a combination of analytical and numerical methods. The technique emphasizes achieving the required field homogeneity with a shorter magnet having a minimum amount of ampere turns. The code calculates the total inductance of the set of coils, total conductor length, force, and maximum field on each coil. The code also calculates the allowable geometrical tolerance to achieve the field uniformity. The code is flexible and can be used for various geometries. Here, we present three different cases to demonstrate the efficiency of the code. First, we present the design details of a 1.5 m long 1.5 T actively shielded magnet, where the stray field is reduced to less than 4 gauss outside the sphere of radius 3.65 m using a pair of shielded coils. A total of four pairs of coils provide a field uniform to within 5.2 parts per million (ppm) within a sphere of 50 cm diameter. Calculated values of all the higher order moments lie within a few ppm. Second, we describe optimized geometry of unshielded 1.5 T symmetric magnets having three pairs of coils. Third, we optimize the geometry of a 1.2 m long 1 T asymmetric magnet having five coils. Here, the good field region starts at 20 cm from one of the edges of the magnet, providing the attending physician better accessibility to the patient. But the ampere turns and computation time required are quite large compared to a symmetric magnet.