Transformations between sensory representations are shaped by neural mechanisms at the cellular and the circuit level. In the insect olfactory system, the encoding of odor information undergoes a transition from a dense spatiotemporal population code in the antennal lobe to a sparse code in the mushroom body. However, the exact mechanisms shaping odor representations and their role in sensory processing are incompletely identified. Here, we investigate the transformation from dense to sparse odor representations in a spiking model of the insect olfactory system, focusing on two ubiquitous neural mechanisms: spike frequency adaptation at the cellular level and lateral inhibition at the circuit level. We find that cellular adaptation is essential for sparse representations in time (temporal sparseness), while lateral inhibition regulates sparseness in the neuronal space (population sparseness). The interplay of both mechanisms shapes spatiotemporal odor representations, which are optimized for the discrimination of odors during stimulus onset and offset. Response pattern correlation across different stimuli showed a nonmonotonic dependence on the strength of lateral inhibition with an optimum at intermediate levels, which is explained by two counteracting mechanisms. In addition, we find that odor identity is stored on a prolonged timescale in the adaptation levels but not in the spiking activity of the principal cells of the mushroom body, providing a testable hypothesis for the location of the so-called odor trace.