A solution of the forward problem is an important component of any method for computing the spatio-temporal activity of the neural sources of magnetoencephalography (MEG) and electroencephalography (EEG) data. The forward problem involves computing the scalp potentials or external magnetic field at a finite set of sensor locations for a putative source configuration. We present a unified treatment of analytical and numerical solutions of the forward problem in a form suitable for use in inverse methods. This formulation is achieved through factorization of the lead field into the product of the moment of the elemental current dipole source with a "kernel matrix" that depends on the head geometry and source and sensor locations, and a "sensor matrix" that models sensor orientation and gradiometer effects in MEG and differential measurements in EEG. Using this formulation and a recently developed approximation formula for EEG, based on the "Berg parameters," we present novel reformulations of the basic EEG and MEG kernels that dispel the myth that EEG is inherently more complicated to calculate than MEG. We also present novel investigations of different boundary element methods (BEM's) and present evidence that improvements over currently published BEM methods can be realized using alternative error-weighting methods. Explicit expressions for the matrix kernels for MEG and EEG for spherical and realistic head geometries are included.