It's a matter of practice.

As mentioned above, you can't do a true track stand on a freewheel bike. But I've gotten pretty good at finding a sweet spot where I can roll back and forth just enough to hold me up. If I find a really sweet spot, I can hold a track stand through an entire light cycle. Most days, about a minute is my limit.