BACKGROUND: Electromagnetic stimulation of the nervous system has the advantage of reduced discomfort in activating nerves. For brain structures stimulation, it has become a clinically accepted modality. Coil designs usually consider factors such as optimization of induced power, focussing, field shape etc. In this study we are attempting to find the effect of the coil contour shape on the electrical field distribution for magnetic stimulation. METHOD AND RESULTS: We use the maximum of the induced electric field stimulation in the region of interest as the optimization criterion. This choice required the application of the calculus of variation, with the contour perimeter taken as a pre-set condition. Four types of coils are studied and compared: circular, square, triangular and an 'optimally' shaped contour. The latter yields higher values of the induced electrical field in depths up to about 30 mm, but for depths around 100 mm, the circular shape has a slight advantage. The validity of the model results was checked by experimental measurements in a tank with saline solution, where differences of about 12% were found. In view the accuracy limitations of the computational and measurement methods used, such differences are considered acceptable. CONCLUSION: We applied an optimization approach, using the calculus of variation, which allows to obtain a coil contour shape corresponding to a selected criterion. In this case, the optimal contour showed higher intensities for a longer line along the depth-axis. The method allows modifying the induced field structure and focussing the field to a selected zone or line