We study the counting statistics of ultracold bosonic atoms that are released from an optical lattice. We show that the counting probability distribution of the atoms collected at a detector located far away from the optical lattice can be used as a method to infer the properties of the initially trapped states. We consider initial superfluid and insulating states with different occupation patterns. We analyze how the correlations between the initially trapped modes that develop during the expansion in the gravitational field are reflected in the counting distribution. We find that for detectors that are large compared to the size of the expanded wave function, the long-range correlations of the initial states can be distinguished by observing the counting statistics. We consider counting at one detector, as well as the joint probability distribution of counting particles at two detectors. We show that using detectors that are small compared to the size of the expanded wave function, insulating states with different occupation patterns, as well as supersolid states with different density distributions can be distinguished.