Yes, Warhammer and Warhammer 40,000 (often abbreviated as Warhammer 40K or simply 40K) are set in the same fictional universe, but they are distinct time periods within that universe.
Warhammer, also known as Warhammer Fantasy Battles, is a tabletop wargame set in a fantasy world. It features various races, such as humans, elves, dwarves, orcs, and others, engaged in epic battles for power and dominance. The setting of Warhammer is characterized by a dark and gritty atmosphere, with elements of magic, medieval warfare, and mythical creatures.
Warhammer 40,000, on the other hand, is a science fiction tabletop wargame set in the far future, specifically in the 41st millennium. It portrays a dystopian universe where different factions, including the Space Marines, the Imperium of Man, Chaos Space Marines, and various alien species, engage in constant warfare across the galaxy. Warhammer 40K is known for its grimdark setting, advanced technology, and a heavy emphasis on futuristic warfare.
While both Warhammer and Warhammer 40,000 share similarities in terms of their tabletop gaming mechanics and themes of conflict, they represent different eras within the same overarching fictional universe. Each has its own distinct lore, characters, and storylines, but they are interconnected through the broader mythology and history of the Warhammer universe.