Charge separation and lightning formation in a thuderstorm is explicitly simulated using spectral bin microphysics the Hebrew University Cloud Model (HUCM) with resolution of 50 m. The model microphysics is based on solving equations for eight size distribution functions for aerosols, drops, three types of ice crystals, aggregates, graupel and hail. Each size distribution is defined on a mass grid containing 43 bins. The model describes the processes of nucleation of cloud particles, diffusion growth, collisions between all types of hydrometeors, differential sedimentation. freezing, melting, breakup of droplets and aggregates. etc. using the equations basing on the first principles, without any parameterization assumptions. Turbulence effects on droplet collisions are taken into account. Charge separation is calculated by collisions between graupel, hail and ice crystals in the presence of liquid water. The charge obtained by particles as a result of collisions depends on the particle size, the temperature, the presence of liquid water, following laboratory results by Takahashi. These charges are transported by convective motions and differential sedimentation depending on mass and type of particles air density. The charges are redistributed between different hydrometeors in course of particle collisions, as well as during freezing, melting and breakup. These charge transformations create time dependent electricity field. The field of electrical potential is determined by solving the Poisson equation. The recursive procedure similar to that developed by Mansell (2002) is used to calculate the lightning path with connects zones where the potential gradients exceeded the breakdown threshold. The relationship between lightning intensity and cloud microstructure is investigated. It is shown, for instance, that increase in aerosol concentration leads to increase of mass of super cooled water aloft, as well as to increase in the ice crystal concentration at the upper levels. It is shown that lightning in maritime clouds is determined to a significant degree by small aerosols which produce ice crystals and graupel at high levels. In continental clouds aerosols foster formation of hail. Thus, production of hail and process of lightning are caused by similar microphysical mechanism. The intensity of lightning can be a measure of the intensity of convection. The relation between the lightning intensity and hail size is discussed.