Gird cells are located in at the enthrorhinal cortex. They fire at regular intervals as an animal navigates an open area, allowing it to understand its position in space by storing and integrating information about location, distance, and direction.

Hexagonal firing patterns.

Grid cells derive their name from the fact that connecting the centers of their firing-fields gives a triangular grid.
Each grid cell has multiple firing fields arranged in a regular, hexagonal pattern across the environment.
→ They have periodic activity patterns as a function of position.

Grid cells evolved early, for navigational tasks, and also constitute place cells. But, in the formation of the neocortex, they were repurposed for maps to all kinds of things, concepts, …

Grid cells can represent any n-dimensional space (slicing up n-dimensional space into multiple two-dimensional slices).

Grid cells are invariant to contextual pertubations

Grid cells activate based on location, independently of other context. Specifically, the ones in the medial enthrorhinal cortex only care about space, in the sense that they perform path integration, i.e. track change from action to action, regardless of environmental context (this is in contrast to the place cell).
This path integration is how you are able to navigate a room in in the dark, for example.

References

Relating transformers to models and neural representations of the hippocampal formation