We count the number of nonzero states in the spatio-temporal or spatial patterns of cellular automata. By observing self-similar structures, we determine the number of nonzero states in the pattern. For Rule 90 and Rule 150 of one-dimensional elementary cellular automata, we provide an overview of previous studies on the number of nonzero states in spatio-temporal patterns until the finite time step 2n − 1. In this study, we calculate the numbers in spatial patterns for each time step t∈Z≥0 that allow us to compute future activities more efficiently than that by simulating the entire spatio-temporal pattern. We obtain results regarding the numbers for Rule 90, Rule 150, a generalization of Rule 90 to a two-dimensional case, and a modified Ulam’s model, which is a two-dimensional crystal growth model. In addition, we examine the relationship between spatio-temporal patterns generated by cellular automata and a singular function. Representing the number of nonzero states by specific numeric values, we show that they are described by a difference form of the singular function.