Introduction

The rodent hippocampal formation encodes spatial information in a world-centered (‘allocentric’) coordinate system1,2. In particular, place cells in the hippocampus proper, alongside grid, border and head-direction cells in the medial entorhinal cortex, are believed to form the neural basis of a so-called ‘cognitive map’3,4,5,6,7. However, a reciprocal transformation between self-centered (‘egocentric’) and allocentric coordinate systems is essential for spatial navigation and episodic memory function8. Specifically, sensory information reaches the brain in an egocentric frame of reference, and must be transformed to viewpoint-invariant allocentric encoding to form a cognitive map. Conversely, spatial information from the allocentric cognitive map must be transformed into a first-person, egocentric frame of reference to support mental imagery and guide spatial navigation9.

Recent studies have described egocentric spatial coding in a range of cortical regions including the dorsomedial striatum10, parietal11,12, lateral entorhinal13, postrhinal14, retrosplenial15,16, prefrontal17 and sensory cortices18. In particular, ‘center-bearing’ cells, which code for the angular offset between an animal’s current heading direction and the center of the recording environment; and ‘center-distance’ cells, which code for the corresponding distance to the center of the recording environment, have each been described in postrhinal cortex, one synapse upstream of MEC14,19. Similarly, egocentric boundary cells, which code for the presence of an environmental boundary at a specific angular offset and distance from the animal, have been described in postrhinal cortex, dorsomedial striatum and retrosplenial cortex10,15,20. Each of these representations could be combined with head direction to construct a map of allocentric space and support navigation to salient locations in an environment8,9,14,20. However, whether ‘pure’ allocentric and egocentric spatial representations coexist within the same local cortical circuits has yet to be established.

To address this question, we looked for evidence of egocentric coding in the firing patterns of well-isolated single units recorded predominantly in the deeper layers of MEC while rats freely foraged for food pellets in an open arena. Although the majority of cells encoded allocentric head direction, consistent with previous reports21, we also identified a significant proportion that were tuned to the ‘pure’ egocentric bearing and / or distance to the center or boundaries of the environment, or to a conjunction of allocentric head direction and egocentric bearing20. The properties of these egocentric spatial cells are similar to those previously described in postrhinal cortex, remaining stable in darkness and across different recording environments, being anchored to the local environment when it was rotated relative to visual cues, and disrupted by the removal of local boundaries14,19. In addition, we found that MEC egocentric cells exhibit weak theta rhythmicity, in contrast to co-recorded grid and head direction cells. These findings demonstrate a unity of spatial coding in MEC, where interactions between egocentric and allocentric spatial representations might guide efficient navigation in the mammalian brain.

Results

Allocentric and egocentric spatial codes coexist in MEC

To investigate whether MEC neurons might encode egocentric information, nine Long-Evans rats were implanted with 16-channel microdrives targeting MEC (Fig. 1a, Supplementary Fig. 1 and Supplementary Table 1). Four rats were excluded from subsequent analyzes due to tetrode locations bordering postrhinal cortex. In the remaining five animals, 976 single units were well-isolated22 (Supplementary Fig. 2; during free foraging for randomly scattered food pellets in the open arena. The majority of these (745, or 76.3%) were located in the deep layers IV, V, and VI, while the remainder (231, or 23.7%) were in the superficial layers II and III (Supplementary Fig. 3a).

Fig. 1: Coexistence of allocentric and egocentric spatial representations in MEC.
figure 1

a Nissl staining of tetrode track in the MEC. The red arrowhead indicates electrolytic lesion. Animal number is shown in the top left. Scale bar, 1 mm. b Diagram illustrating allocentric head-direction (HD), egocentric center-bearing (CB) and center-distance (CD). The horizontal line to the right / east wall of the arena acts as a reference orientation for calculating both allocentric head direction and the bearing between the rat’s current head direction and center of the environment. c Two representative examples of center-bearing cells from rat MEC. Left panels, color-coded path trajectory (gray line) with superimposed directional spike locations (color indicates the center-bearing; color bar shows the directional range). Right panels, center-bearing and head-direction tuning curves, with mean vector length (MVL) inset. (i) and (ii) indicator of two example cells, as the same for panels d-f. d Same as c except for representative head-direction cells (color indicates the head direction; color bar shows the directional range). e Representative center-distance cells and their tuning curves, with R2 of the center-distance - firing rate relationship inset. f Representative examples of conjunctive center-bearing × head-direction × center-distance cells, with MVL of directional tuning curves and R2 of distance tuning curves inset. g Comparison of MVL values for center-bearing cells (left panel) and head-direction cells (right panel) according to head direction and movement direction. h Distribution of preferred firing directions for center-bearing cells (left panel) and head-direction cells (right panel). Source data are provided as a Source Data file.

Egocentric cells were defined as those encoding egocentric bearing (i.e. the relative angle to a reference point such as the center of an environment from the animal’s current head direction) and / or egocentric distance (the relative distance to a reference point from the animal’s current location14; Fig. 1b). Head-direction or egocentric bearing cells were classified as those with both mean vector length (MVL) and intra-trial angular stability exceeding the 99th percentile of a randomly shuffled distribution (Supplementary Fig. 4 and Supplementary Fig. 5). Egocentric distance cells were defined as those with linear fit parameter R2 and intra-trial distance tuning stability exceeding the 99th percentile of a randomly shuffled distribution (Supplementary Fig. 4 and Supplementary Fig. 5).

Surprisingly, we found that MEC cells encoded spatial information in both allocentric and egocentric reference frames. In line with previous work21, a large proportion of MEC cells (317, or 32.5%) showed stable, allocentric head-direction tuning (Mean ± SEM MVL = 0.42 ± 0.01, 5th and 95th percentiles = 0.20 and 0.83, respectively; Fig. 1d, Supplementary Fig. 6 and Supplementary Fig. 7) with an even distribution of preferred orientations (Rayleigh test, r = 0.05, P = 0.44; right panel, Fig. 1h). Notably, however, a large proportion of cells (230, or 23.6%) showed similarly stable, egocentric head-direction tuning relative to the geometric center of the environment, i.e. were center-bearing cells14 (Fig. 1c and Supplementary Fig. 8). Although the preferred orientations of these cells were distributed evenly across the 360° range (Rayleigh test, r = 0.05, P = 0.56; left panel, Fig. 1h), they were clustered around 0, 90, 180 and 270 degrees (i.e. firing strongly when the geometric center was in front, on the left, behind, or on the right of the animal, respectively, circular V-test for an angular shift of 0° after mod operation of 90°, V = 9.95, P < 0.001). In addition, both head-direction and center-bearing cells were more strongly tuned to the animal’s (relative) head direction than its movement direction (Fig. 1g).

As well as cells encoding heading direction in allocentric and egocentric coordinates, the firing rate of 125 cells (12.8% of the total) showed either a positive (88/125, or 70.4%) or negative (37/125, or 29.6%) linear correlation with current distance to the geometric center of the environment, i.e. were center-distance cells14 (Fig. 1e and Supplementary Fig. 9). Some cells also exhibited conjunctive coding for both allocentric and egocentric spatial information (Fig. 1f and Supplementary Fig. 6). Specifically, 89 cells (9.12% of the total) showed conjunctive coding for both head-direction and center-bearing (Supplementary Fig. 10); 71 cells (7.27% of the total) showed conjunctive coding for both center-bearing and center-distance (Supplementary Fig. 11); and 28 cells (2.87% of the total) exhibited head-direction, center-bearing and center-distance tuning properties (Supplementary Fig. 12).

Based on average firing rate and spike width23,24, we classified MEC neurons as either putative excitatory regular-spiking or inhibitory fast-spiking neurons. According to this criterion, 49.2% (n = 480/976) of recorded cells were classified as regular-spiking and 7.07% (n = 69/976) as fast-spiking, with the remaining 43.75% (n = 427/976) being unclassified (Supplementary Fig. 13a and b). Crucially, we observed a low percentage of putative interneurons in both egocentric and allocentric spatial cells (Supplementary Fig. 13c-e).

To confirm that the center of the environment was the reference point to which the population of egocentric cells was tuned, we divided the 1 m × 1 m arena into 2.5 cm-sided spatial bins. We then systematically calculated the egocentric directional and distance tuning of each cell to all spatial bins and found that the geometric center produced both the strongest directional tuning and best linear distance fit (Supplementary Fig. 14). Importantly, we also recorded 29 grid cells (2.97% of the total) and 67 border cells (6.86% of the total), consistent with previous reports6,7 (Supplementary Fig. 15 and Supplementary Fig. 16). Moreover, we frequently co-recorded both grid (n = 12 across 9 sessions) and border (n = 24 across 15 sessions) cells on the same bundle of four tetrodes as center-bearing or center-distance cells, confirming that these responses coexisted in MEC (Supplementary Fig. 15 and Supplementary Fig. 16).

Next, we examined whether MEC cells also encode the presence of boundaries at a specific angle and distance relative to the animal10,15. Interestingly, an equally large proportion of cells (271, or 27.8%) exhibited egocentric boundary tuning (Supplementary Fig. 17a). Moreover, those egocentric boundary cells (EBCs) showed a large overlap with center-bearing cells, with 193 cells (71.2% of EBCs, or 83.9% of center-bearing cells) passing both classification criteria (Supplementary Fig. 17b and 17c). This is unsurprising, given that it is difficult to dissociate center-bearing and egocentric boundary responses in small, regularly shaped environments19. All subsequent analyzes in the main text focus on center-bearing cells, with equivalent results for EBCs shown in the Supplementary Information (Supplementary Figs. 18-22). Importantly, we observed no qualitative differences between the responses of center-bearing and EBC populations to any of the environmental manipulations described below.

Previous research has shown that spatial responses are distributed throughout MEC in a layer-dependent manner. While grid cells are predominantly found in layer II, head-direction and conjunctive grid × head-direction cells tend to occupy the deeper layers21 (III to VI). Consistent with this, we found that allocentric head-direction cells were more often found in deep layers (Layers II/III versus deep Layers IV/V/VI, 19.1% versus 36.6%, χ2 test, P < 0.001, Supplementary Fig. 3b). Similarly, center-bearing and center-distance cells were more often found in deep layers (Layers II/III versus deep Layers IV/V/VI, center-bearing cells: 9.52% versus 27.9%, χ2 test, P < 0.001; center-distance cells: 4.3% versus 15.4%, χ2 test, P < 0.001, Supplementary Fig. 3b), like those described previously in postrhinal cortex14. Neurons in deeper layers send extensive axonal connections to the superficial layers25,26, where grid cells are predominantly located21. As such, these results suggest that grid cells in superficial layers could integrate both allocentric and egocentric spatial information from deep layers to perform path integration27.

MEC egocentric cells remain stable in darkness

Head-direction cells typically preserve their preferred firing directions in darkness, suggesting that they can be maintained by self-motion cues when visual inputs are impoverished5,28. To test whether MEC egocentric cells exhibit similar stability, we recorded four animals across a total of 27 sessions in light and dark conditions (Fig. 2a). Consistent with previous studies, the preferred firing directions of head-direction cells were stable in darkness (n = 38, median angular shift = -8.93°, circular V-test for an angular shift of 0°, V = 34.0, P < 0.001, Fig. 2b). Similarly, center-bearing cells showed little drift in their preferred firing directions between light and dark conditions (n = 39, median angular shift = 2.98°, circular V-test for an angular shift of 0°, V = 34.8, P < 0.001, Fig. 2c). In addition, center-distance cells maintained their tuning slopes in darkness (n = 37, Pearson’s product moment correlation, r = 0.97, Fig. 2d). These results indicate that MEC egocentric cells – like those described previously in postrhinal cortex14 - preserve their tuning properties when visual input is diminished.

Fig. 2: MEC egocentric spatial representations remain stable in darkness.
figure 2

a Representative firing patterns of egocentric and allocentric cells under light and dark conditions. (i) A center-bearing cell recorded across three consecutive sessions in light, dark and light conditions. Color-coded path trajectory (gray line) with superimposed directional spike locations (color indicates the center-bearing; color bar shows the directional range) are shown for each session, alongside the center-bearing and head-direction tuning curves with MVL values inset. (ii) Same as (i) but for a center-distance cell. Distance tuning curves have R2 of the center-distance – firing rate relationship inset. (iii) Same as (i) but for a head-direction cell. b Distribution of angular shifts in preferred firing direction between the first light session and dark session for all 38 head-direction cells. c Same as b except for 39 center-bearing cells. d Comparison of distance tuning slopes between the first light session and dark session for 37 center-distance cells. Source data are provided as a Source Data file.

MEC egocentric cells are anchored to the local environment

Visual input from local landmarks can exert control over head-direction cells, with rotation of prominent cues most often leading to a similar rotation in their preferred firing direction29. Hence, we next investigated whether local cues would similarly influence the tuning properties of egocentric center-bearing cells. To do so, we recorded four animals across a total of 20 sessions before and after rotating the recording environment by 45° in a clockwise or counter-clockwise direction relative to the recording room (Fig. 3a). Consistent with previous research, MEC head-direction cells remained anchored to local visual inputs, maintaing their preferred firing directions relative to the running box (n = 32, median angular shift = -6.32°, circular V-test for an angular shift of 0°, V = 29.4, P < 0.001, Fig. 3b). Similarly, the preferred firing direction of center-bearing cells relative to the environment remained almost unchanged (n = 20, median angular shift = 8.92°, circular V-test for an angular shift of 0°, V = 17.4, P < 0.001, Fig. 3c). Finally, the tuning properties of center-distance cells also persisted in the rotated arena (n = 22, Pearson’s product moment correlation, r = 0.94, Fig. 3d). These results indicate that the firing properties of MEC egocentric cells—like those described previously in postrhinal cortex14 - remain anchored to the geometry of the local recording environment.

Fig. 3: MEC egocentric spatial representations are anchored to the local environment.
figure 3

a Representative firing patterns of egocentric and allocentric cells during rotation of the recording environment relative to the recording room. (i) A center-bearing cell recorded across consecutive standard, 45° cue rotation, and standard sessions. (ii) Same as (i) but for a center-distance cell. (iii) Same as (i) but for a head-direction cell. Directional tuning curves have MVL values inset, and distance tuning curves have R2 of the center-distance – firing rate relationship inset. b Distribution of angular shift in preferred firing directions for 32 head-direction cells between the first baseline recording session and rotated session. The angular shift was calculated relative to the local visual cue. c The same as b except for 20 center-bearing cells. d Comparison of distance tuning slopes between the first baseline recording session and cue rotation session for 22 center-distance cells. Source data are provided as a Source Data file.

MEC egocentric cells maintain their spatial tuning across environments

Allocentric head direction cells typically maintain their firing patterns and relative angular offset across recording environments30. Hence, we next investigated whether the tuning of center-bearing and center-distance cells would be maintained across environments with distinct geometry. To do so, we recorded five animals across a total of 30 sessions in square and circular arenas (Fig. 4a). These recording enclosures were placed in the same location in the same experimental room, with a single intra-maze white cue card placed at an equivalent location inside each enclosure. In line with previous findings31, head-direction cells maintained their preferred firing direction when the geometry of the recording environment was altered (n = 41, median angular shift = -5.95°, circular V-test for an angular shift of 0°, V = 38.4, P < 0.001, Fig. 4b). Similarly, the tuning of center-bearing cells remained stable in the circular recording environment (n = 31, median angular shift = 8.93°, circular V-test for an angular shift of 0°, V = 26.9, P < 0.001, Fig. 4c). Finally, center-distance cells maintained their distance tuning across both environments (n = 25, Pearson’s Product Moment Correlation, r = 0.92, Fig. 4d). These results indicate that MEC egocentric cells – like those described previously in postrhinal cortex14 – are insensitive to environmental geometry.

Fig. 4: MEC egocentric spatial representations are insensitive to environmental geometry.
figure 4

a Representative firing patterns of co-recorded egocentric and allocentric cells across recording environments with differing geometry. (i) A center-distance cell recorded across three consecutive sessions in the square, circular, and square boxes. (ii) Same as (i) but for a center-distance cell. (iii) Same as (i) but for a head-direction cell. Directional tuning curves have MVL values inset, and distance tuning curves have R2 of the center-distance - firing rate relationship inset. b Distribution of angular shift in preferred firing directions for 41 head-direction cells between the first square enclosure session and circular enclosure session. c The same as b but for 31 center-bearing cells. d Comparison of distance tuning slopes between the first baseline recording session and cue rotation session for 25 center-distance cells. Source data are provided as a Source Data file.

MEC egocentric spatial tuning depends on physical boundaries

Sensory inputs, for example visual, somatosensory and vestibular afferents, are likely to play a crucial role in generating egocentric spatial representations. For example, physical boundaries provide direct somatosensatory input that has been shown to be essential for egocentric boundary vector tuning in retrosplenial cortex15. Similarly, the firing patterns of center-distance (but not center-bearing) cells in postrhinal cortex are disrupted by the removal of environmental boundaries19. To examine the influence of physical boundaries on MEC egocentric tuning, we recorded from four animals across a total of 13 sessions in the standard recording enclosure and during exploration of an elevated platform without walls (Fig. 5a).

Fig. 5: MEC egocentric spatial representations are degraded in environments without physical walls.
figure 5

a Representative firing patterns of egocentric and allocentric cells in an elevated platform without walls. (i) A center-bearing cell recorded across consecutive baseline (B), elevated platform (E), and second baseline (B’) sessions. (ii) Same as (i) but for a center-distance cell. (iii) Same as (i) but for a head-direction cell. Directional tuning curves have MVL values inset, and distance tuning curves have R2 of the center-distance - firing rate relationship inset. b Distribution of MVL values for 25 head-direction cells across sessions. All data are presented as mean values +/− SEM. Two-sided Wilcoxon signed-rank test, B-E, Z = -0.63, P = 0.53; E-B’, Z = -0.90, P = 0.37; B-B’, Z = -0.63, P = 0.53. c Same as b but for 51 center-bearing cells. Two-sided Wilcoxon signed-rank test, B-E, Z = -5.48, P < 0.001; E-B’, Z = -5.14, P < 0.001; B-B’, Z = -0.57, P = 0.57. d The change in MVL values for center-bearing cells between the first baseline session and elevated platform session. Black dots represent cells that still exhibit significant center-bearing selectivity on the elevated platform, while red dots represent cells that no longer reach our classification criteria. e Distribution of R2 values for 18 center-distance cells across sessions. Two-sided Wilcoxon signed-rank test, B-E, Z = -3.59, P < 0.001; E-B’, Z = -2.98, P = 0.003; B-B’, Z = -1.63, P = 0.10. Source data are provided as a Source Data file.

Center-bearing responses were disrupted in the absence of physical borders, with mean vector length decreasing significantly in the elevated platform (E) session compared to a baseline session in the standard recording enclosure (B) (n = 51, two-sided Wilcoxon signed-rank test, B-E, Z = -5.48, P < 0.001; E-B’, Z = -5.14, P < 0.001; B-B’, Z = -0.57, P = 0.57; Fig. 5c). As a result, the majority of center-bearing cells (32/51, or 62.7%) no longer passed our classification criteria on the elevated platform (Fig. 5d). Center-distance tuning was also degraded, with a significant decrease in the linear fit between firing rates and distance to the center of the elevated platform (n = 18, two-sided Wilcoxon signed-rank test, B-E, Z = -3.59, P < 0.001; E-B’, Z = -2.98, P = 0.003; B-B’, Z = -1.63, P = 0.10; Fig. 5e). As a result, the majority of center-distance cells (13/18, or 72.2%) also failed to pass our classification criteria on the elevated platform. Finally, border cell firing was also disrupted, with border scores decreasing significantly on the elevated platform (n = 13, two-sided Wilcoxon signed-rank test, B-E, Z = -3.18, P < 0.01; E-B’, Z = -3.18, P < 0.01; B-B’, Z = -0.45, P = 0.65). As a result, the majority of border cells (12/13, or 92.3%) no longer passed our classification criteria on the elevated platform (Supplementary Fig. 23e-h).

In contrast, head-direction tuning was unaffected by the absence of physical boundaries, with no significant change in mean vector length across recording sessions (n = 25, two-sided Wilcoxon signed-rank test, B-E, Z = -0.63, P = 0.53; E-B’, Z = -0.90, P = 0.37; B-B’, Z = -0.63, P = 0.53). Hence, the majority of head-direction cells (15/25, or 60%) still passed our classification criteria on the elevated platform (Fig. 5b). Similarly, grid cell firing patterns persisted on the elevated platform, with no significant change in gridness scores across recording sessions (n = 5, two-sided Wilcoxon signed-rank test, B-E, Z = -1.21, P = 0.23; E-B’, Z = -1.75, P = 0.08; B-B’, Z = -0.94, P = 0.35). Indeed, all grid cells continued to pass our classification criteria on the elevated platform (Supplementary Fig. 23a–d).

In sum, these results indicate that MEC egocentric tuning depends on physical boundaries. This is consistent with previous reports of degraded egocentric tuning in the absence of explicit borders in the retrosplenial cortex15 but contrasts with the firing patterns of center-bearing cells in postrhinal cortex, which are less significantly affected by moving to a raised platform19. Similarly, allocentric border cell firing patterns are degraded, consistent with previous reports of boundary related responses in entorhinal cortex6, but in contrast to boundary vector cell firing in the subiculum3. Finally, allocentric head direction tuning remains unaffected by wall removal, unlike similar responses in postrhinal cortex, which were degraded under these conditions19.

MEC egocentric cells scale with environmental expansion

We next sought to determine whether the tuning curves of MEC egocentric cells scale with the size of the local environment or have a stable relationship with respect to the geometric center (Fig. 6a). To do so, we recorded from four animals across a total of 15 foraging sessions in the standard 1 m × 1 m enclosure (S) and a larger 1.5 m × 1.5 m enclosure (L). These recording enclosures were placed in the same location in the same experimental room, with a single intra-maze white cue card of the same size placed at an equivalent location inside each enclosure.

Fig. 6: MEC center-distance cells encode relative distance.
figure 6

a Representative responses of egocentric and allocentric cells in recording environments of different sizes. (i) A representative center-bearing cell recorded across consecutive sessions in small (S, 1 m × 1 m), large (L, 1.5 m × 1.5 m), and small (S’, 1 m × 1 m) enclosures. (ii) Same as (i) but for a center-distance cell. (iii) Same as (i) but for a head-direction cell. Directional tuning curves have MVL values inset, and distance tuning curves have R2 of the center distance - firing rate relationship inset. b Distribution of angular shift in preferred firing directions for 34 head-direction cells between the first small enclosure session and large enclosure session. c The same as b but for 20 center-bearing cells. d Comparison of distance tuning slopes between the first small enclosure session and large enclosure session for 16 center-distance cells. e Ratio of distance tuning slopes between the first small enclosure session and large enclosure session for 16 center-distance cells. Two-sided Wilcoxon signed-rank test, S-L, Z = -3.41, P < 0.01; L-S’, Z = -3.19, P < 0.01; S-S’, Z = -1.93, P = 0.05. Data are presented as mean values +/- SEM. fh Comparison of peak firing rates across recording sessions for 34 head-direction cells (f ), 20 center-bearing cells (g) and 16 center-distance cells (h). Two-sided Wilcoxon signed-rank test, head-direction cells, S-L, Z = -1.24, P = 0.22; L-S’, Z = -0.65, P = 0.52; S-S’, Z = -1.07, P = 0.29; center-bearing cells, S-L, Z = -1.61, P = 0.11; L-S’, Z = -1.16, P = 0.25; S-S’, Z = -0.22, P = 0.82; center-distance cells, S-L, Z = -1.24, P = 0.22; L-S’, Z = -1.86, P = 0.06; S-S’, Z = -0.78, P = 0.44. The box plot represents the interquartile range (IQR), with the lower and upper edges indicating the first (Q1) and third quartiles (Q3), respectively. The line inside the box marks the median (Q2). The whiskers extend to the smallest and largest values within 1 times the IQR from Q1 and Q3. Source data are provided as a Source Data file.

We found that the firing rate of center-distance cells increased or decreased more rapidly with distance from the center of the smaller recording environment (n = 16, two-sided Wilcoxon signed-rank test, S-L, Z = -3.41, P < 0.01; L-S’, Z = -3.19, P < 0.01; S-S’, Z = -1.93, P = 0.05; Fig. 6d), with the absolute slope being 2.14 ± 0.25 and 1.75 ± 0.18 times steeper in the first and second sessions in the smaller enclosure than in the larger enclosure, respectively (Fig. 6e). In contrast, the preferred firing directions of head-direction cells (n = 34, median angular shift = 0°, circular V-test for an angular shift of 0°, V = 32.1, P < 0.001, Fig. 6b) and center-bearing cells (n = 20, median angular shift = -8.93°, circular V-test for an angular shift of 0°, V = 16.3, P < 0.001, Fig. 6c) remained unchanged in recording environments of different sizes.

Notably, the peak firing rate of all three cell types also remained unchanged between the smaller and larger enclosures (two-sided Wilcoxon signed-rank test, head-direction cells, S-L, Z = -1.24, P = 0.22; L-S’, Z = -0.65, P = 0.52; S-S’, Z = -1.07, P = 0.29; center-bearing cells, S-L, Z = -1.61, P = 0.11; L-S’, Z = -1.16, P = 0.25; S-S’, Z = -0.22, P = 0.82; center-distance cells, S-L, Z = -1.24, P = 0.22; L-S’, Z = -1.86, P = 0.06; S-S’, Z = -0.78, P = 0.44; Fig. 6f–h). Hence, MEC center-distance cells appear to code for relative (rather than absolute) distance from the center of the current environment, rescaling the slope of their tuning curves in arenas of different sizes. This is partially consistent with the firing properties of center-distance cells in postrhinal cortex, which show mixed responses to environmental rescaling, with some cells maintaing a fixed slope (i.e. coding for absolute distance) and others dynamically adjusting to the new arena size14.

MEC egocentric cells exhibit weak theta rhythmicity

Theta (4-11 Hz) band oscillations are prominent in the MEC local field potential (LFP) during active movement32,33, and allocentric spatial cells (such as grid cells) typically show strong entrainment to the theta rhythm34,35,36. Hence, we next asked whether MEC egocentric cells were also theta modulated. Consistent with previous observations, we detected strong theta oscillations in the MEC LFP (Fig. 7a, b). However, compared with head-direction cells (Fig. 7c), of which 19.6% (62/317) showed theta rhythmicity, only 4.78% (11/230) of pure center-bearing cells (Fig. 7d) and 7.87% (7/89) of conjunctive center-bearing × head-direction cells exhibited significant theta rhythmicity—a significantly lower proportion (χ2 test, P < 0.001 and P = 0.009, respectively; Fig. 7i, j). In contrast, grid cells showed the most prevalent theta rhythmicity of all cell types examined here (13/29, or 44.8%), while similar proportions of center-distance (Fig. 7e, 19/125, or 15.2%) and border cells (14/67, or 20.9%) exhibited significant theta rhythmicity (χ2 test, P = 0.32; Fig. 7i, j, Supplementary Fig. 24). However, we note that it is difficult to dissociate border and center-distance cell firing patterns in the small recording environments used here, and so these two populations may overlap substantially.

Fig. 7: MEC egocentric spatial cells are rarely theta-rhythmic.
figure 7

a Representative local field potential (LFP) recorded during 2 s of active running. Lower plot, unfiltered LFP trace; upper plot, 4-11 Hz band-pass filtered LFP trace. b Representative power spectral density of LFP from the whole recording session in a. Note the prominent ~9 Hz theta peak. c A representative theta-rhythmic head-direction cell. d A representative non-theta-rhythmic center-bearing cell. e A representative non-theta-rhythmic center-distance cell. f A representative theta phase-locking head-direction cell. g A representative theta phase-locking center-bearing cell. h A representative theta phase-locking center-distance cell. Left panels, color-coded path trajectory (gray line) with superimposed directional spike locations (color indicates the center-bearing or head-direction; color bar shows the directional range) or firing rate map. Left middle panels, center-bearing, head-direction and center-distance tuning curves, with mean vector length (MVL) and R2 of the center-distance - firing rate relationship inset. Right middle panels, Spike-time autocorrelograms. Right panels, firing phase distribution. i Relative proportion of each cell type showing theta-rhythmic firing. Filled portions of each bar represent the proportion of theta-rhythmic cells. χ2 test, ***P < 0.001, n.s., P > 0.05. j Distribution of theta rhythmicity indices (TRI) for each cell type. Two-sided Mann–Whitney U test, ***P < 0.001, n.s., P > 0.05. The box plot represents the interquartile range (IQR), with the lower and upper edges indicating the first (Q1) and third quartiles (Q3), respectively. The line inside the box marks the median (Q2). The whiskers extend to the smallest and largest values within 1.5 times the IQR from Q1 and Q3. k Same as (i) except for theta phase-locking cells. χ2 test, ***P < 0.001, *P < 0.05, n.s., P > 0.05. Source data are provided as a Source Data file.

Next, we assessed theta phase-locking in MEC spatial cells. In contrast to the weak theta-rhythmicity described above, theta phase-locking was more prevalent (Fig. 7k). Specifically, 68.5% (217/317) of head-direction cells (Fig. 7f), 52.2% (120/230) of center-bearing cells (Fig. 7g) and 63.2% (79/125) of center-distance cells (Fig. 7h) showed significant theta phase-locking – a significantly higher ratio than those with spike train theta-rhythmicity (χ2 test, all P < 0.001; Fig. 7k). Grid cells again showed the most prevalent theta phase-locking (22/29, or 75.9%) with a consistent preferred phase (Supplementary Fig. 24i), as described by previous studies33. Besides theta phase-locking, MEC neurons have also been shown to fire at progressively earlier phases of the theta cycle as their firing fields are traversed33,34, a phenomenon known as theta phase precession35. Here, we found that the majority of MEC spatial cells showed little phase precession, with the notable exception of grid cells, of which 27.6% (8/29) exhibited significant theta-precession (Supplementary Fig. 25).

The weak theta-rhythmicity of MEC egocentric cells is similar to that observed for egocentric boundary cells in retrosplenial cortex, which rarely exhibit rhythmic spiking despite the strong LFP theta oscillation15. The absence of theta phase precession in MEC egocentric cells also implies that they encode spatial information in firing rates alone, rather than exploiting the theoretical advantages offered by temporal coding35,36.

Functional connectivity between MEC allocentric and egocentric cells

The co-existence of allocentric and egocentric representations suggests that MEC may be one locus of coordinate transformations between spatial reference frames in the brain. Crucially, this would require functional synaptic connections between each population of cells. To establish whether such connections exist, we examined spike-time cross-correlations for 1137 pairs of co-recorded cells (Fig. 8a–d), with putative monosynaptic connections being revealed by short-latency interactions37.

Fig. 8: Functional connectivity between MEC egocentric and allocentric spatial cells.
figure 8

a Putative monosynaptic connections between one center-bearing × center-distance cell, one center-bearing cell and one center-distance cell revealed by their spike-time cross-correlograms. Left panels, color-coded path trajectory (gray line) with superimposed directional spike locations (color indicates the center bearing or head direction; color bar shows the directional range) for head-direction or center-bearing cells, firing rate maps for center-distance cells. Middle panels, head-direction, center-bearing or center-distance tuning curves, with MVL value or R2 of the center-distance vs firing rate relationship inset. Corresponding tetrode number and unit number are indicated above the waveforms recorded on the four tetrode contacts. Color-coded triangles represent different types of spatial cells denoted below panel. Scale bar, 500 μs and 200 μV. Right panels, spike timing cross-correlograms with hypothesized synaptic connectivity indicated schematically above. Red dashed lines indicate confidence bounds, green lines indicate the predicted value. b Putative monosynaptic connections between a center-bearing × center-distance cell, a center-distance cell and a center-bearing ×  center-distance cell. c Putative monosynaptic connections between a head-direction cell, a center-bearing cell and a center-bearing × center-distance cell. d Putative monosynaptic connections between a head-direction cell, a center-bearing cell, and another center-bearing cell. e Heatmap showing the ratio of monosynaptic connection pairs among MEC allocentric, egocentric and conjunctive cells. f Heatmap of normalized monosynaptic connection frequency between MEC allocentric, egocentric and conjunctive cells. Source data are provided as a Source Data file.

In total, we identified 86 monosynaptic connections between pairs [Fig. 8e, including 4/124 (3.23%)] of allocentric (e.g. border, grid or head-direction) and egocentric (e.g. center-bearing, center-distance or egocentric boundary) cells and 6/124 (4.84%) between egocentric and allocentric cells, each of which is more than expected by chance (binomial test with expected P0 = 0.01, P = 0.037 and P = 0.002, respectively). However, the largest ratio of connectivity occurred within and between egocentric and conjunctive cells (i.e. those that encoded spatial information in both egocentric and allocentric reference frames; binomial test with expected P0 = 0.01, all P < 0.001, Fig. 8f). In contrast, monosynaptic connections from allocentric cells to other allocentric cells, from allocentric cells to conjunctive cells and vice versa, were no more likely than expected by chance (binomial test with expected P0 = 0.01, P = 0.20, 0.49 and 0.25, respectively). In sum, egocentric cells and conjunctive cells in the deeper layers are extensively interconnected, suggesting that the local synaptic connectivity required to support coordinate transformations between egocentric and allocentric spatial representations might exist within MEC.

Reconstructing the spatial code of egocentric and allocentric MEC cells with a generalized linear model

Finally, we sought to confirm that the egocentric spatial firing patterns described above could not arise from purely allocentric spatial coding. To do so, we used a generalized linear model (GLM) to assess how well allocentric and egocentric predictors could account for the observed firing properties of different spatial cells recorded in MEC15,38; Supplementary Fig. 26 and Fig. 27). For center-bearing, center-distance, and conjunctive center-bearing × center-distance cells, we found that egocentric predictors alone were sufficient to reconstruct the observed firing patterns. Conversely, firing patterns of head-direction cells could be accurately reproduced using allocentric predictors alone. These results demonstrate that spatial information in a single reference frame was sufficient to replicate the tuning properties of our observed egocentric and allocentric spatial cells.

In addition, we applied both a population vector (PV) decoding algorithm with a linear filter and a Bayesian decoding algorithm to estimate center-bearing and center-distance from the ensemble spiking activity of all MEC cells39,40,41,42. Both methods exhibited good decoding performance, with the Bayesian algorithm outperforming the PV and linear filter approach11,13,43. This demonstrates that egocentric center-bearing and center-distance cells are sufficient to provide the animal with a continuous estimate of the direction and distance to a specific anchor point within the environment throughout navigation.

Discussion

Efficient navigation and memory function requires continuous, reciprocal transformations between information encoded in allocentric and egocentric reference frames. The results presented here demonstrate that single cells encoding spatial information in both reference frames co-exist in rodent MEC (Supplementary Fig. 29). Specifically, we have demonstrated that MEC neurons not only encode allocentric spatial information in the well-described firing patterns of grid, border, and headdirection cells6,7,21; but also egocentric spatial information in the firing patterns of center-distance, center-bearing, and egocentric boundary cells. Similar firing patterns have previously been reported in a variety of other brain regions10,11,12,13,14,15,16,18,20,43, but this is the first time that cells encoding purely egocentric spatial information have been shown to exist in MEC.

Crucially, the coexistence of allocentric and egocentric spatial representations alongside head-direction modulated versions of each supports theoretical models that have proposed a head-direction modulated neural circuit that can transform boundary-related firing patterns between allo- and ego-centric reference frames8,9,44,45. Moreover, it implies that one locus of that transformation circuit in the rodent brain may be MEC, instead of (or in addition to) the retrosplenial cortex, as suggested previously. The existence of putative monosynaptic connections between allocentric and egocentric cells described here is consistent with the presence of a transformation circuit in MEC. Importantly, this circuit should also be capable of transforming the object-related firing patterns observed in and around MEC13,46 between spatial reference frames. Finally, although the egocentric spatial responses described here during random foraging encode the relative distance and direction to the geometric center of the environment, it is possible that these firing patterns could become anchored to other, more salient locations with experience. This could subsequently support direct navigation to those locations without the need for allocentric spatial coding47. On the other hand, the fact that egocentric center-bearing and center-distance responses were disrupted when the physical walls of the environment were removed (like those of allocentric border cells), and that center-distance responses scaled with the size of the environment, suggests that each cell type might actually encode the relative location of (physical) boundaries rather than the geometric center of the arena. The use of more complex and irregular shaped recording environments would help to dissociate these possibilities19.

Where might the egocentric spatial information encoded in MEC originate from? This region receives inputs from sensory areas including visual and posterior parietal afferents48,49 as well as projections from retrosplenial cortex50, each of which preferentially target the deeper layers of MEC51,52 where the majority of egocentric spatial responses were detected. Another potentially important source of input originates from postrhinal cortex, but these projections preferentially target the superficial layers of MEC53,54. Finally, our recent work has demonstrated that sensory cortices, including somatosensory and visual cortex, contain various allocentric55,56,57,58 and egocentric18 spatial representations. Besides, the medial prefrontal cortex contains both allocentric and egocentric border representations17. Each of these regions also has reciprocal connections with MEC59,60.

How do the spatial responses described here differ from those previously reports in postrhinal cortex14,19? First, head direction tuning is sharper in MEC, compared to the broader and more sinusoidal tuning curves in postrhinal cortex14. Second, head direction responses in MEC are not degraded by the removal of physical boundaries, in contrast to those in postrhinal cortex19. Interestingly, the spatial tuning of allocentric grid cells in MEC also persists on the elevated platform, unlike that of co-recorded egocentric cells. This suggests that egocentric spatial tuning relies more strongly on somatosensory inputs that are absent when physical boundaries are removed, while grid cells might rely more strongly on self-motion information, consistent with previous theoretical and empirical studies7.

Why was MEC egocentric tuning not seen in previous studies? First, those studies have mainly targeted the superficial layers of MEC14, rather than the deeper layers in which we found the majority of egocentric cells. Second, we have recorded a relatively large sample of single neurons (n = 976), which helps to ameliorate fluctuations in the proportion of each cell type observed across animals (Supplementary Table 1). Finally, one study did report that 12% of MEC neurons were head-direction modulated egocentric boundary cells20. Our findings complement and extend those results by fully characterizing the range and characteristics of egocentric spatial responses observed in MEC.

In conclusion, our results suggest that MEC neurons exhibit both allocentric and egocentric spatial tuning, and that MEC may therefore support the transformation of spatial information between reference frames during the construction and use of cognitive maps. Understanding the interactions between allocentric and egocentric spatial codes within and beyond MEC is likely to be critical in understanding both spatial navigation and episodic memory function.

Methods

Subjects

Five male Long-Evans adult rats (2–4 months, ~250–450 grams) were individually housed in acrylic transparent cages (W ×  L × H: 35 cm × 45 cm × 45 cm) in a temperature (19–23 °C) and humidity (55–70%) controlled environment with a 12 h/12 h reversed light/dark cycle. This manuscript shared the same source of recorded animals (#MEC1-#MEC5 in Supplementary Fig. 1) of a previous paper of our own, which discovered of a type of distinct bipolar head-direction cells in the MEC61. All behavioral sessions were conducted during the dark phase. Animals can access water freely with partial food deprivation to maintain their body weight at around 85-90% of free-feeding weight to encourage exploration. Food was restricted 8-24 hours before each training and recording session. All experimental procedures were performed in accordance with the National Animal Welfare Act under a protocol with the permission license number #SYXK-2017002 approved by the Animal Care and Use Committee from both the Army Medical University and Xinqiao Hospital.

Surgical procedures and microdrive implantation

Rats were anesthetized with isoflurane mixed with oxygen (1.5-3.0% in O2), fixed in a stereotaxic frame (David Kopf Instruments, Tujunga, California, USA) and kept on a heating pad with a feedback system for automatically temperature control at 37 °C. After the midline incision, a screw was positioned behind the eye as a ground electrode.

Microdrives were implanted to target the medial entorhinal cortex (MEC), 0.2-0.8 mm anterior to the transverse sinus, 4.5-4.7 mm lateral to the midline and 1.5-1.8 mm below the dura. Microdrives were slightly tilted in the sagittal plane at an angle of 10 - 12° in the anterior direction, secured with dental cement and 8–10 anchor screws. Each microdrive was composed of four tetrodes, which were assembled with four 17 µm Platinum/Iridium wires (#100167, California Fine Wire Company) and moved together as a whole. The impedance of each electrode was reduced to between 150 and 300 kΩ at 1 kHz through electroplating (nanoZ; White Matter LLC, Seattle, Washington, USA). After fixation of the microdrive, rats were given the analgesic Temgesic before being returned to their home cages.

Electrophysiology

One week after the operation, rats were acclimated to the behavioral training, tetrode turning and signal recording procedures before the initiation of experiments. Rats were trained to freely forage for randomly scattered food pellets in a 1 m × 1 m black square box polarized by a white cue card (297 mm × 210 mm) placed inside the enclosure at a location midway between two corners with the bottom aligned to the floor. Each behavioral session lasted around 20–40 min to facilitate full coverage of the recording arena. Tetrodes were lowered in steps of 25 or 50 µm until single units could be well isolated. Neural signals were acquired by an Axona system (Axona Ltd., St. Albans, U.K.) at a sample rate of 48 kHz (50 samples per waveform, 8 bits/sample), band-pass filtered in a frequency range of 0.3-7.0 kHz and amplified with a gain of × 5 − 18k. Local field potential was recorded from one of the electrodes, amplified × 2 − 5k times and low-pass filtered with a cutoff frequency of 500 Hz. Data collection began when signal amplitudes exceeded ~four times the noise level (root mean square 20–30 µV).

Spike sorting and behavioral correlates

To identify well-isolated single units, spikes were manually sorted offline at the end of each recording session with graphical cluster-cutting software (TINT, version 4.4.16, Axona Ltd, St. Albans, U.K.). The clustering procedure was based on spike waveform features (peak-to-trough amplitude and width), together with spike time auto- and cross- correlations. Similar or identical waveforms were only counted once across consecutive recording sessions. To evaluate the quality of spike sorting, we utilized two measures of unit isolation quality, Lratio and Isolation Distance22. Only units with Lratio < 1 were included for further analysis.

The rat’s behavior was monitored with a video camera installed on the ceiling directly above the recording arena and two light-emitting diodes (LEDs) of different sizes were attached to the headstage to track the position, orientation and running speed of the animal. To minimize the effect of confounding behaviors such as immobility, grooming and rearing on the neural signals, only spikes with rat’s instantaneous running speed > 2.5 cm/s were included in subsequent analyzes.

Single units with > 100 spikes in recording sessions with a spatial coverage of > 80% were included for further analyzes. Tracking data were smoothed with a 400 ms boxcar filter, and occupancy computed for 2.5 cm × 2.5 cm spatial bins. Total spike counts and occupancy maps were smoothed individually with a quasi-Gaussian kernel over the neighboring 5 bins × 5 bins. Spatial firing rate maps were then generated by dividing smoothed spike counts by smoothed occupancy.

We determined the burstiness of each unit by calculating the ratio of spikes with interspike intervals < 10 ms to the total number of spikes emitted23,62. Speed modulation was quantified using a previously described method63. Briefly, running speed was computed from the tracking data using a Kalman filter and Rauch-Tung-Striebel (RTS) smoother, and instantaneous firing rate was computed in 20 ms bins and smoothed with a 400 ms Gaussian filter. A speed score was then computed as the Pearson product-moment correlation between those two variables.

Finally, we classified putative regular spiking excitatory neurons as cells with an average firing rate below 5 Hz and a peak-to-trough spike width below 350 µs, based on a two-component Gaussian fit to the distribution of spike widths; and fast-spiking interneurons as cells with an average firing rate above 5 Hz and a peak-to-trough spike width below 350 µs (Supplementary Fig. 13).

Identification of head-direction cells

The rat’s head direction was computed from the relative position of the two LEDs mounted on the headstage. Conversely, movement direction was calculated as the instantaneous derivative of the tracked position. The head direction tuning curve for each recorded unit was determined by computing the firing rate as a function of the rat’s head direction in 3° bins, smoothed with a 15° box-car filter. To avoid potential sampling biases, data were only included for further analysis if all directional bins were covered by the animal before smoothing64. Head direction (HD) was defined as:

$${{{\rm{\theta }}}}_{{HD}}=\arctan 2\, ({y}_{S}-{y}_{L},{x}_{S}-{x}_{L})$$

where \(({x}_{S},{y}_{S})\) and \(({x}_{L},{y}_{L})\) are the spatial coordinate of the small and large LED, respectively.

The strength of directional tuning was quantified by computing the mean vector length (MVL) of the circular distribution of firing rates, computed using the following equation:

$${{\rm{MVL}}}=\frac{\sqrt{{\left({\sum }_{i}^{n}{F}_{i}\,*\, \cos \left({{{\rm{\theta }}}}_{i}\right)\right)}^{2}+{\left({\sum }_{i}^{n}{F}_{i}*\sin \left({{{\rm{\theta }}}}_{i}\right)\right)}^{2}}}{{\sum }_{i}^{n}{F}_{n}}$$

where \({F}_{i}\) is the firing rate in bin i, \({{{\rm{\theta }}}}_{i}\) is the head direction angle in bin i, and n is the total number of directional bins. The preferred firing direction was defined as the head direction with the highest firing rate across all directional bins.

Head-direction cells were defined as cells with mean vector length exceeding the chance level, which was determined by a shuffling process using all recorded units. For each round of the shuffling process, the entire sequence of spike trains from each unit was time-shifted along the animal’s trajectory by a random period between 20 s after the trial onset and the trial duration minus 20 s, with the end wrapped to the beginning of the trial. A directional tuning curve was then constructed, and mean vector length was calculated. This procedure was repeated 100 times for each unit, generating a total of 97600 permutations for the 976 MEC units. The distribution of mean vector length across all 100 random permutations of all identified units was derived, and the chance level was defined as the 99th percentile of the shuffled distribution.

Classification of head-direction cells was further refined by angular stability, which was computed by calculating the correlation between two directional tuning curves from the first and second halves of the same recording session. Threshold value for angular stability was determined by a shuffling procedure performed in the same way as for mean vector length. Only head-direction cells with angular stability higher than chance level were included for further analysis.

Identification of center-bearing cells

The angle of center-bearing was defined as the relative angle between the animal’s head direction (computed as described above) and the angle from the animal itself to the geometric center (GC), which was defined as:

$${{{\rm{\theta }}}}_{{GC}}=\arctan 2({y}_{C}-{y}_{L},{x}_{C}-{x}_{L})$$

where \(({x}_{C},{y}_{C})\) and \(({x}_{L},{y}_{L})\) were the coordinate of the geometric center and the animal’s position, respectively. Finally, center-bearing (CB) was defined as the difference between those two angles:

$${{{\rm{\theta }}}}_{{CB}}={{{\rm{\theta }}}}_{{GC}}-{{{\rm{\theta }}}}_{{HD}}$$

Center-bearing cells are defined as cells with both mean vector length and intra-trial angular stability higher than the 99th percentile of shuffled data, which were derived in the same way as for head-direction cells.

Identification of center-distance cells

Center-distance (CD) was defined as the instantaneous distance of the animal’s location to the geometric center of the environment:

$${{\rm{CD}}}=\sqrt{{({x}_{C}-{x}_{L})}^{2}+{({y}_{C}-{y}_{L})}^{2}}$$

where \(({x}_{C},{y}_{C})\) and \(({x}_{L},{y}_{L})\) were the coordinate of the geometric center and the animal’s position, respectively.

To generate center-distance tuning curves, spike counts and occupancy time in each 2 cm center-distance bin was calculated. The distance tuning curve was then determined by dividing the total spike count by the occupancy time for each distance bin. A linear regression fit was computed on the distance tuning curve and the R2 value (coefficient of determination) and slope were then derived. The R2 value of the fit was defined as the distance tuning strength. To quantify distance tuning stability, distance tuning curves from the first and second halves of the recording session were smoothed with a 6-cm box-car filter, and the correlation between the two distance tuning curves was calculated. Center-distance cells were defined as cells with both R2 and intra-trial stability higher than the 99th percentile of shuffled data.

Identification of grid cells

Grid cells were quantified using the gridness score according to previously published methods7,64,65. First, spatial autocorrelations were calculated using smoothed firing rate maps according to:

$$r({\tau }_{x},{\tau }_{y})=\frac{n\sum \lambda \left(x,y\right)\, \lambda \left(x-{\tau }_{x},y-{\tau }_{y}\right)-\sum \lambda \left(x,y\right)\sum \lambda \left(x-{\tau }_{x},y-{\tau }_{y}\right)}{\sqrt{n\sum {\lambda \left(x,y\right)}^{2}-{[\sum \lambda \left(x,y\right)]}^{2}}\sqrt{n\sum {\lambda \left(x-{\tau }_{x},y-{\tau }_{y}\right)}^{2}-{[\sum \lambda \left(x-{\tau }_{x},y-{\tau }_{y}\right)]}^{2}}}$$

where \(\lambda \left(x,y\right)\) is the mean firing rate of the corresponding unit at the coordinate of \(\left(x,y\right)\), and the summation was over n pixels for both \(\lambda \left(x,y\right)\) and \(\lambda (x-{\tau }_{x},y-{\tau }_{y})\) (\({\tau }_{x}\) and \({\tau }_{y}\) denote the spatial lags). Autocorrelations were not calculated for spatial lags of \({\tau }_{x}\), \({\tau }_{y}\) where n < 20.

Second, the gridness score was calculated for each unit by comparing values along a circle centered on the central peak of the auto-correlogram but excluding the central peak itself, with rotated versions of those values21,65. Specifically, Pearson’s correlations between the circular sample and its rotated versions were computed, with 60° and 120° angles of rotation in the first group, and 30°, 90° and 150° angles of rotation in the second group. The gridness score was defined as the minimal difference between any of the coefficients in the first group and any of the coefficients in the second group.

Grid cell classification was verified using the same method as for head-direction cells. Specifically, the distribution of gridness scores was calculated for the entire set of permutation trials from all recorded units, and grid cells were defined as cells with both gridness scores and intra-trial spatial stability higher than the 99th percentile threshold derived from the shuffled data.

Identification of border cells

The border score for defining border cells was computed according to previously published methods6,64,65. Specifically, the border score was defined as the difference between the maximal length of any single spatial firing field of the cell touching any of the four walls (\({c}_{M}\)) and the mean distance of all the firing fields to the nearest wall (\({d}_{m}\)), divided by the sum of those two values:

$$b=\frac{{c}_{M}-{d}_{m}}{{c}_{M}+{d}_{m}}$$

The border score ranged from −1 for cells with central firing fields to +1 for cells with firing fields that adhered exactly to at least one entire wall. Spatial firing fields were defined as a region of neighboring pixels with firing rates higher than 0.3 times that unit’s maximum firing rate which covered a total area of at least 200 cm2.

Border cell classification was verified using the same method as for head-direction cells. Specifically, the distribution of border scores was calculated for the entire set of permutation trials from all recorded units, and border cells were defined as cells with both border scores and intra-trial spatial stability higher than the 99th percentile threshold derived from the shuffled data.

Identification of egocentric boundary cells

To quantify whether MEC cells exhibited egocentric boundary tuning, we constructed egocentric boundary rate maps (EBRs) according to previously published methods10,15. This quantifies the tuning of MEC cells to nearby boundaries at a specific bearing and distance relative to the animal. Specifically, every intersection from the animals’ current location and head direction to the nearest geometric borders in increments of 3° were calculated, and the corresponding distances organized into 2.5 cm bins (if their length was smaller than half the size of the arena). The procedure was repeated for each spike fired by a given cell and converted into an egocentric polar rate map by dividing the total number of spikes by the duration of occupancy of each spatial bin.

To calculate the strength of egocentric boundary tuning, we computed the mean vector as

$${{\rm{MV}}}=\frac{{\sum }_{\theta }^{n}{\sum }_{d}^{m}{F}_{\theta,d}\,*\,{e}^{i\,*\, \theta }}{{\sum }_{\theta }^{n}{\sum }_{d}^{m}{F}_{\theta,d}}$$

Where θ is the angular bin relative to the animal’s head direction, d is the distance bin from the animal’s position, \({F}_{\theta,d}\) is the firing rate in the θ-d bin, n is the total number of orientation bins, and m is the total number of distance bins. The mean vector length (MVL) is defined as the absolute value of MV and used to quantify the strength of egocentric boundary tuning.

Egocentric boundary cell classification was verified using the same method as for head-direction cells. Specifically, the distribution of MVL values was calculated for the entire set of permutation trials from all recorded units, and egocentric boundary cells were defined as cells with MVL higher than the 99th percentile threshold derived from the shuffled data.

Environmental manipulations

During light/darkness sessions, rats were first allowed to freely forge in the open arena in the light condition with a background luminance around 15 lux. A dark session followed this session with all lights and computer monitors switched off, resulting in a nearly zero lux background luminance. Then a final standard light session was performed.

In experiments with different geometric shapes, rats were first tested in the square arena (1 m × 1 m), followed by a recording in the circular enclosure (diameter = 0.9 m), before returning to the square box.

For visual landmark rotation, rats were first tested in the standard recording environment followed by a 45° rotation of the square arena in the clockwise or counterclockwise direction relative to the room. Next, another standard session was performed with the square arena rotated back to the original position.

For recording in the elevated platform without physical walls, a raised platform 50 cm above the ground was constructed. Rats were first tested in the standard recording environment, followed by the recording in the elevated platform without walls, and then a final recording session was conducted in the standard baseline condition.

For recording in a larger environment, rats were first tested in the standard 1 m × 1 m square arena, followed by a recording session in a larger 1.5 m × 1.5 m square arena before returning to the standard box for another baseline recording session.

Theta rhythmicity

To examine theta rhythmicity, MEC local field potentials (LFPs) were zero-phase filtered with 4 Hz and 5 Hz stop- and pass-band low cut-off frequencies, respectively, and 10 Hz and 11 Hz pass- and stop-band high cut-off frequencies, respectively. Power spectra were then computed as the fast Fourier transform (FFT) of the spike-train auto-correlogram, including only spikes fired at a running speed of > 2.5 cm/s. A cell was classified as being theta rhythmic if the mean spectral power within a 1 Hz band on either side of a peak in the 4–11 Hz theta frequency range was at least five times higher than that from 0 to 125 Hz (this ratio being defined as theta rhythmicity index, TRI)58.

Theta phase-locking

To examine theta phase-locking, we used the Hilbert transform to derive the phase of the band-pass filtered LFP at each time point. We then extracted theta phase values for each spike fired by each cell, computed the preferred firing phase as the circular mean of these values, quantified theta phase-locking as the MVL of these values, and used the Rayleigh test to establish if theta phase-locking was greater than expected by chance.

Theta phase precession

To quantify theta precession in MEC spatial cells, we used a previously described method that does not rely on identifying discrete firing fields33. Specifically, the unwrapped theta firing phase of each spike was extracted, the autocorrelation of these cumulative phase values was computed, and the power spectrum of that phase autocorrelation within a four-cycle window was generated. Cells that exhibit theta phase-locking will show a peak in the spike phase autocorrelation power spectrum at a frequency of one cycle, whereas cells that exhibit theta phase precession will show a peak at a higher frequency. A cell was considered to show significant theta phase precession if the mean integrated power at peak ± 0.025 of the spike phase autocorrelation power spectrum was 50% greater than that in the 0.5-0.85 and 1.3-1.8 bands33. Only neurons where the peak of the spike phase autocorrelation was >5 spikes were included in these analyzes.

Cross-correlogram and putative monosynaptic connections

Putative monosynaptic synaptic connections between allocentric and egocentric cells were identified by analyzing spike train cross-correlograms according to a previously published method37. Briefly, spike-time cross-correlograms between a reference and target cell were generated with a bin size of 0.4 ms, then convolved with a finite window using a partially hollow Gaussian kernel with a standard deviation of 10 ms and hollowed fraction of 60%66. Next, the upper and lower confidence limits were estimated from a Poisson distribution with Bonferonni correction. If the peak within the monosynaptic window (±4 ms) in the cross-correlogram exceeded that from the upper confidence bound, then the short-latency interactions were considered as putative monosynaptic excitatory connections. For neuron pairs co-recorded on the same electrode, the 0-1.6 ms range of the cross-correlogram was not considered as superimposed spikes could not be resolved by the clustering procedure67. Finally, for two cells recorded on the same tetrode with putative monosynaptic connections, if the cross-correlogram’s -3-0 ms range was significantly lower than the lower confidence bound, the connection was excluded to account for the possible refractory period from bursting firing.

Histology

After the recordings were completed, rats were deeply anaesthetized with sodium pentobarbital (0.01 ml/g). In one rat (MEC#5), an electrolytic lesion was then made by passing a small current (20 µA, 15 s) through two active electrodes of the microdrive. Finally, rats were perfused intracardially with phosphate-buffered saline (PBS) followed by 4% paraformaldehyde (PFA). Brains were removed from the skull and post-fixed in 4% PFA at 4°C overnight before transferring into 20% and 30% sucrose/PFA solution sequentially across 72 hours. 30 µm thick sagittal sections were serially cut using a cryostat and were mounted on glass slides.

Brain sections were stained with Cresyl Violet acetate (C5042, Sigma-Aldrich, USA), after which tetrode tracks were examined using an Olympus Slideview VS200 Digital Slide Scanner (Olympus, Japan). The final recording positions were estimated from the deepest tetrode track according to the daily notes on tetrode advancement. The tissue shrinkage correction was calculated by dividing the distance between the brain surface and electrode tips by the final depth of the tetrodes. Tetrode traces were confirmed to be located in MEC based on the reference figures (from Fig. 179 to 180) published in the seventh edition of The Rat Brain in Stereotaxic Coordinates68. Because of the limited spatial resolution of the recovered electrode track, clear differentiation between layers IV, V, and VI was not always possible. Hence, we collectively refer to these as the ‘deep layers’.

Generalized linear model

Generalized linear models (GLMs) were used to evaluate the firing pattern of cells predicted by spatial information in different reference frames. We assumed that the probability of observing a specific spike count for each cell in any given time bin was amenable to an inhomogeneous Poisson process, and that spatial predictors alone could be used to predict the firing rate in each time bin. The two main spatial predictors we wished to test incorporated purely allocentric or egocentric information as follows:

$${f}_{{ego}}={{{\rm{\alpha }}}}_{1}\sin \left(\theta \right)+{\alpha }_{2}\cos \left(\theta \right)+{\alpha }_{3}{dis}+{\alpha }_{4}{dis}\,*\, \sin \left(\theta \right)+{\alpha }_{5}{dis}\,*\, \cos (\theta )$$
$${f}_{{allo}}={{{\rm{l}}}}_{1}\sin \left(\gamma \right)+{{{\rm{l}}}}_{2}\cos \left(\gamma \right)+{\lambda }_{3}x+{\lambda }_{4}y$$

where \({f}_{{ego}}\) and \({f}_{{allo}}\) are the egocentric and allocentric predictors, \(\theta\) is the center bearing, \({dis}\) is the distance of the rat from the center of the environment, \(\gamma\) is the head direction, and \({\mathrm{x\&y}}\) are the allocentric position of the rat in the environment. The variables \(\alpha\) and \({{\rm{l}}}\) were coefficients to be fit by the model. We then assessed how the firing patterns of different spatial cells observed in the experimental data could be accounted for by GLMs that incorporated purely egocentric, purely allocentric, or both sets of predictors (the full model) as follows:

Full model:

$$\begin{array}{c}{\lambda }_{{full}}={e}^{{\, f}_{{ego}}+{f}_{{allo}}}\end{array}$$

Egocentric model:

$${\lambda }_{{ego}}={e}^{{\, f}_{{ego}}}$$

Allocentric model:

$${\lambda }_{{allo}}={e}^{{\, f}_{{allo}}}$$

where \(\lambda\) was the firing rate within a given time bin. Finally, the number of spikes generated by a given cell in a given time bin was generated at random according to a Poisson process as follows:

$$\Pr (n)=\frac{{\lambda }^{n}}{n!}\,*\,{e}^{-\lambda }$$

The Akaike Information Criterion (AIC) uses a model’s maximum likelihood estimation (log-likelihood) as a measure of fit. The smaller the AIC, the better the model fit. To reflect the coding preference of cells, \({dACI}\) was defined as follows:

$${AIC}=-2{\mathrm{ln}}(L)+2k$$
$${dAIC}={AI}{C}_{{allo}}-{AI}{C}_{{ego}}$$

where \(L\) is the maximized likelihood function, \(k\) is the number of parameters, and \({AI}{C}_{{allo}}\) and \({AI}{C}_{{ego}}\) are the \({AIC}\) values calculated using the allocentric and egocentric models, respectively. In sum, the activity of a cell could be better predicted using spatial information in an egocentric (or allocentric) coordinate system when the \({dAIC}\) was greater (or less) than 0.

Decoding direction and distance to the geometric center

We used both a Population Vector (PV) algorithm with linear filter and Bayesian algorithm to decode center bearing and center distance in each time bin from the activity of egocentric spatial cells. Center bearing was discretized into 120 directional bins and center distance in the standard recording environment (100 cm × 100 cm) into 100 location bins. We then constructed a surrogate trajectory and spike train for each center-bearing and center-distance cell because the number of simultaneously recorded cell was limited. The surrogate spike train of a cell was randomly sampled from the raw spike train of that cell when the relevant behavioral correlate (center-bearing or center-distance) in each trajectory was matched. For example, if the center bearing within a given time bin of the surrogate trajectory was 90°, the spike count of a given center-bearing cell in that time bin was randomly sampled from the set of time bins in the raw spike train where the center bearing was also 90°.

The population vector (PV) algorithm utilized the ensemble preferred firing directions of the center-bearing (or head-direction) cells to construct the directional unit vector and derive the final direction by the sum of preferred firing direction vectors from all cells weighted by their respective firing rate as follows:

$${{Ang}}_{t}={\sum }_{i=1}^{N}{r}_{i,t}*\vec{{C}_{i}}$$

where \({{Ang}}_{t}\) is the angle (center-bearing or head direction) decoded at time \(t\), \({r}_{i,t}\) is the firing rate of cell \(i\) at time \(t\), and \(\vec{{C}_{i}}\) the preferred vector. Only center-bearing cells whose tuning curves were approximately sinusoid were selected to provide the center-bearing vector, and the preferred firing direction of each center-bearing cell was defined as the mean directional vector of each cell.

At the same time, a simple linear filter was used to decode center distance based on the relationship between center distance and firing rate.

$${{Dis}}_{{tr}}={R}_{{tr}}f$$
$${{Dis}}_{{decoded}}={R}_{{surrogated}}f$$

where \({{Dis}}_{{tr}}\) is a vector of center distances from the ‘training’ surrogate trajectory, \({R}_{{tr}}\) a matrix of firing rates across all center-distance cells, \(f\) is the linear coefficient fit during that surrogate trajectory, and \({Di}{s}_{{decoded}}\) is the center distance decoded from a second ‘test’ surrogate trajectory.

For comparison, a Bayesian neural decoding strategy was also applied to the surrogate spike trains described above to decoded the posterior probability of center bearing and center distance in each time bin as follows:

$$\Pr \left({Ang}|{Num}\right)=\frac{{\rm{Pr}}\left({Num}|{Ang}\right)\,*\, \Pr ({Ang})}{\Pr ({Num})}$$
$$\Pr \left({Num}|{Ang}\right)={\prod }_{i=1}^{N}\Pr \left({{Num}}_{i}|{Ang}\right)={\prod }_{i=1}^{N}\frac{{\left(\tau \,*\,{R}_{i}\left({Ang}\right)\right)}^{{n}_{i}}}{{n}_{i}!}\,*\,{e}^{-\tau\,*\,{R}_{i}\left({Ang}\right)}$$
$$\Pr \left({Ang}|{Num}\right)=C\left({\prod }_{i=1}^{N}{\left({R}_{i}\left({Ang}\right)\right)}^{{n}_{i}}\right)*{e}^{-\tau {\sum }_{i=1}^{N}{R}_{i}({Ang})}$$

Where the posterior probability \(\Pr \left({Ang},|,{Num}\right)\) is calculated using Bayes’ rule, the prior distribution \(\Pr ({Ang})\) is taken to be uniform across directions, \(\tau\) is the duration of each time bin, \({n}_{i}\) is the number of spikes fired by the \(i\)-th cell in each time bin, \({R}_{i}\left({Ang}\right)\) is the mean firing rate in each directional bin, the probability of \({Num}\) spikes being generated by the cell in each time bin was assumed to be Poissonian, and \(C\) is a normalization constant that depends on \(\tau\) and \({n}_{i}\) to ensure that the probability distribution sums to 1. Center-distance decoding was the same as center-bearing decoding except for the use of displacement bins in place of angular bins.

To evaluate the performance of center-bearing decoding, we used the circular residual, which is the smaller angular difference between any two given directions. To evaluate the performance of center-distance decoding, we computed the mean offset between the decoded distance to the center and real distance to the center across time bins.

Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.