This article is from the sci.fractals FAQ, by Michael C. Taylor and Jean-Pierre Louvet with numerous contributions by others.
The basic algorithm is: For each pixel c, start with z = 0.
Repeat z = z^2 + c up to N times, exiting if the magnitude of z gets
large. If you finish the loop, the point is probably inside the
Mandelbrot set. If you exit, the point is outside and can be colored
according to how many iterations were completed. You can exit if
|z| > 2, since if z gets this big it will go to infinity. The maximum
number of iterations, N, can be selected as desired, for instance 100.
Larger N will give sharper detail but take longer.
Frode Gill has some information about generating the Mandelbrot Set at