If you’re writing a mystery, it’s generally the case that you’ll hide details from the reader. And it’s inevitable that some details will be omitted (a novel that omits no details will never be finished). But sometimes you want to hide things from readers for other reasons.
In my own writing, every character has some backstory. In those backstories, some of the characters keep secrets, and I want to keep those secrets, too.
The balancing issue in this is that if you hint too often at the secrets, readers may become frustrated if the secret is non-obvious, but if you never hint at them at all, the characters may as well not have secrets. The method that I’ve found works best is to make sure that the character reacts to having a secret, rather than saying that they have a secret. This method has to be modified if the character with a secret is the narrator.
In some books, I’ve seen this done very skillfully. (See, for example, the Broken Earth trilogy by N.K. Jemisin.) In other books, it’s ham-fisted and blunt. I’ll admit to skipping to find out the secret before continuing with certain books. In one book (The Sympathizer), I wish the secret had been kept out of the book entirely.
My primary tip for this is to ensure that your characters react in ways that are internally consistent. This doesn’t mean they have to be externally consistent: those with secrets often make unreliable narrators. Fun, but unreliable.