We study the relation between diffusion and loss of charge produced in X-ray CCDs with the fitting method. We obtain the extent and the pulse height of each X-ray event in a CCD by a two-dimensional image-fitting the charge distribution of the event. For the monochromatic X-rays, we find that the event with small extent keeps all the charge produced, while that with larger extent than a certain value loses some part of the produced charge as a function of extent. The result suggests that the event with a small extent is produced by an X-ray absorbed in the depletion layer. On the other hand, the event with large extent corresponds to an X-ray absorbed in the field-free region. We develop two new methods which enable us to derive the relation between the extent of an event and the absorption depth. One is performed by illuminating well calibrated monochromatic X-ray source. The other is realized by using with two monochromatic X-rays and enables us to measure the thickness of the CCD depletion layer without calibrating absolute flux of the monochromatic X-rays.