The count included males from twenty years old and upward. The stated purpose was to number those able to go to war in Israel. See Numbers 1:2–3.
In Numbers 1:1–4, Yahweh speaks to Moses in the Sinai wilderness at the tent of meeting and gives a specific order: take a headcount of the Israelite community. The counting is not of everyone, but of males, organized by family lines, and specifically those aged twenty and up who are fit for military service. These verses open Numbers by grounding the book in a dated, located command given at Israel’s central worship-and-leadership site, the tent of meeting. The passage sets the agenda for what follows: organizing the people for travel and conflict by listing who belongs where and who can serve.
Numbers 1:1–4 presents the census as a direct instruction from Yahweh to Moses at a specific time and place: the Sinai wilderness, at the tent of meeting, in the second year after the exodus. The passage treats Israel as an organized community with recognized structures (tribes, family groupings, households) and recognized leaders.
A careful answer keeps the immediate passage, the book's argument, and the whole-Bible storyline together, so the question is answered in context instead of as a detached idea.
Start with Numbers 1:2-3, then read the surrounding section so the answer stays connected to the passage's flow.
2Take the sum of all the congregation of the children of Israel, by their families, by their fathers` houses, according to the number of the names, every male, by their polls;
3from twenty years old and upward, all who are able to go forth to war in Israel, you and Aaron shall number them by their hosts.