Until Deputy Commissioner Mark Tatum opens the envelopes Tuesday at the N.B.A. draft lottery at the New York Hilton, he will not know the winner.

Nor will the hopeful representatives from each team, nor the assembled members of the news media, nor the millions watching the revelation on television.

But about 25 people will know because the actual draft lottery will be over, having taken place about an hour earlier in another room of the hotel.

The annual opening of the envelopes is essentially a made-for-TV sideshow; the actual selection of the winning teams takes place in strict secrecy.

The site for the little-seen but crucial event will be a conference room elsewhere in the hotel. A drawing of Ping-Pong balls from a machine like those used in state lotteries will be witnessed by a representative of each team — not the same ones who sit at desks under television lights at the formal announcement — and a few members of the news media. Their cellphones will be confiscated, and no contact with the outside world will be allowed.

Once the drawing is complete, three people will leave the room: two N.B.A. legal officials and Denise Pelli, a partner of the accounting firm Ernst & Young. They will go to a second room, where 14 envelopes and logo cards for each team will be waiting. Everyone else in the first room must remain sequestered until after the televised ceremony.

The envelopes will be prepared, and then Ms. Pelli will be escorted by security guards to a third room, where the ceremony will take place. The N.B.A. officials will remain behind; Ms. Pelli will be the only person in the room who knows what is in the envelopes.

The lottery will be conducted on a machine manufactured by Smartplay International, which is also responsible for weighing and measuring the 14 Ping-Pong balls that are pulled from it.

A timekeeper with a digital stopwatch will stand with his back to the machine. Precisely 20 seconds after it starts, he will signal to the operator to draw a ball. Further signals will come at 10-second intervals until four balls have been pulled.

Although there are 14 teams in the lottery and 14 Ping-Pong balls, that match is just a coincidence. The number of Ping-Pong balls was chosen because there are exactly 1,001 ways that four numbers can be drawn from a set of 14. Each of those combinations is assigned to a team. The Minnesota Timberwolves, who had the worst record this season and have a 25 percent chance of getting the top pick, receive the first 250 combinations: 1, 2, 3, 4; 1, 2, 3, 5; 1, 2, 3, 6 — all the way to 1, 7, 12, 14. The Knicks, the next-worst team, get the next 199 combinations, and so on down to the Oklahoma City Thunder, who have only five combinations and an 0.5 percent chance at the top pick.

The 1,001st and final combination — 11, 12, 13, 14 — is unassigned; if it is drawn, the balls will be put back and drawn again. As in most lotteries, the order in which the balls are drawn does not matter — 1, 3, 9, 12 is considered the same as 3, 12, 9, 1.

Officials will hastily consult a chart and announce to the select few in the room which team has won the top pick. Then the balls will be returned to the hopper, and the second pick will be drawn, by the same process, and then the third. If a team is repeated, that draw will be disregarded and redone until a new team comes up.

Once the top three picks are determined, the lottery will be over. Slots 4 through 14 will be assigned based solely on record. As a result, the Timberwolves, even if they are not pulled in the three draws, will get no worse than the fourth pick.

For Knicks fans, the math looks like this: They have a 19.9 percent chance to have one of their combinations pulled for the top pick, an 18.8 percent chance for pick No. 2, and a 17.1 percent chance for pick No. 3 — in total, a 55.8 percent chance at a top-three pick.

If their combinations are not drawn, they will slip to No. 4 (31.9 percent) or No. 5 (12.3 percent), but no lower.

The lottery will be videotaped and will be posted on the N.B.A.’s website, but only after the televised ceremony is over.

Because of the lottery’s complexity and because revealing the picks in reverse order from 14 to 1 is more dramatic, it is the envelope-opening ceremony that is televised live, not the drawing that really determines who gets the top pick.

The N.B.A.’s method for determining who will get the top pick has grown more complex over time. Before there was the draft lottery, there was a coin flip. Beginning in 1966, the last-place teams in the Eastern and Western Conferences tossed for the right to the No. 1 pick; the loser got No. 2.

In 1985, after mutterings that teams might be losing games intentionally to have a 50-50 chance at the top pick, the league instituted its first lottery: a simple random draw among the seven worst teams. Each team had an envelope, and David Stern, the commissioner at the time, pulled one out of a drum. When he opened the envelope to reveal the Knicks’ logo, it fueled unsubstantiated conspiracy theories that linger to this day: that the envelope had been marked, or even refrigerated, to tip off Mr. Stern.

Since 1990, a weighted system has been used, and it has been tinkered with a few times over the years. Though the system has changed, the grumbling has never stopped. There were those who said, without any evidence, that the Cleveland Cavaliers’ victories in the last two lotteries were engineered to compensate the team for losing LeBron James to free agency.

The lottery exists, in part, to discourage teams from losing games and thereby assuring themselves of the first pick. Yet in many fans’ eyes, there was more tanking this season than ever.

But the lottery does seem to prevent tankers from being unduly rewarded. The last time the team with the worst record got the No. 1 pick was 2004, when Orlando received it.

When the envelopes are opened Tuesday night, it will be a dramatic moment, and the futures of several franchises will be altered. But even as hopeful executives are interviewed and fans cross their fingers, the drama will have already occurred, thanks to a few bouncing Ping-Pong balls in a small conference room downstairs.