What I use for not getting lost is:
1- Use the f3 command to get the coordinates of bases and portals (or whatever you want to note), or at least take a screenshot or smartphone pict of it. This is if all else fails and also helps constructing nether highways. Also note that the coordinates don’t follow the standard +/- convention.
2 - In caves I place torches on the right hand wall, which allows a retreat with torches on the left. I also use 3 on the floor to signify a section that was totally searched and not needed to revisit and 3 on the wall to indicate a tricky section where it may be difficult to find a passage.
3 - In the nether I like to use cobblestone to mark my path, and those other useless stone blocks, but will use anything contrasting to do this. If I’m out stacking Netherite will work in a pinch. Sometimes I will use torches if it’s a path I’m not sure I’m keeping (as the are easy to remove). Lately I have found the occasional use of torches along with cobblestone helpful since they can be seen from a far distance very easily. Before the update I have also found it very worth it to build nether highways, meaning straight paths with minimal and gradual elevations changes that only follow the natural terrain when it’s a major advantage in construction. But one really needs the coordinates to know where they are going. IDK if that’s still a good plan with the nether update.
4 - Use the compass, move at 3 o’clock, come back at 9 o’clock.
5 - Build a tall pillar at my bases, place a campfire on top, burning nethererack or torches. Jump down into water to get back down (or jump to death if bed is nearby and you can recollect your gear).
6 - You can use the direction of the sun/moon but that’s sort of a last resort for me.
7 - In caves if that lost, I enjoy the lost, don’t worry about route finding and make it free explore and I just dig a stairs up when I’m done.