Divide by 8, and round down
One block in the Nether is 8 blocks in the Overworld. Going in, Java Edition divides your X and Z by 8 and rounds down, toward negative infinity, not toward zero. So X 1000 becomes 125, but X −1 becomes −1, not 0, and X −9 becomes −2. Every Overworld block from X 1000 to 1007 leads to Nether X 125, and every block from −8 to −1 leads to −1. Coming back, X and Z are multiplied by 8; where in the Nether block you stand moves you up to 7 blocks, so Nether X 125 brings you out somewhere from 1000 to 1007.
Height
Your Y is not scaled: you arrive at the same height you left. The Nether's ceiling of bedrock sits at Y 127, so a new Nether portal is built at Y 127 or below, while the Overworld runs from Y −64 to 319. The height only matters when choosing between portals, and for where a new portal goes when there is no room for one.
How the game picks a portal
When you arrive, Java Edition looks for an existing portal within 16 blocks of that point along X and along Z in the Nether, or within 128 blocks in the Overworld, at any height. If there are several, the closest wins, measured as a straight line that counts height too. If there are none, it builds a new portal at the closest place with room within 16 blocks, looking down from the top. If nowhere has room, it cuts a space out at your height, kept between Y 70 and 118 in the Nether (70 and 310 in the Overworld), with an obsidian floor. Bedrock Edition searches 128 blocks on both sides, so in Bedrock one Nether portal can catch Overworld portals up to about 1,024 blocks apart.
Linking two portals by hand
To join an Overworld portal to one you build in the Nether, build the Nether one at the coordinates this page gives, then go through from the Overworld side first. Within a block or two is plenty; what matters is that no other portal is closer. The checker under the calculator runs both trips, from A and from B, and says which portal each comes out of and how far it is from where you land.
Large coordinates
Anything up to the world border works, 29,999,984 blocks from the centre. A Nether position whose Overworld match falls outside the border is pulled back to the last block inside it, as the game does.
Questions
Why do two of my Overworld portals go to the same Nether portal?
The game looks 16 blocks around your arrival point in the Nether, which is 128 blocks in Overworld terms. Two Overworld portals less than about 128 blocks apart on both X and Z land close enough to share one Nether portal. Coming back, that portal takes you to whichever Overworld portal is closest to its point times 8, so one of the two can end up with no way back to it.
How far apart do Overworld portals need to be to link separately?
In Java Edition, far enough apart that their Nether points are 17 or more blocks apart along X or Z. 136 Overworld blocks along X or Z always does it; 129 to 135 may or may not, depending on the rounding. Then build each Nether portal at its own coordinates. In Bedrock Edition the Nether search reaches 128 blocks, so Overworld portals need to be about 1,032 blocks apart to get a Nether portal each.
Why did the game build a new portal instead of using mine?
Your portal was more than 16 blocks (Nether) or 128 blocks (Overworld) from the arrival point along X or Z, or a portal block that was once in range was broken. Put the coordinates into the checker to see how far off it was.
Does it work for Bedrock Edition?
Yes. The divide-by-8 is the same; switch to Bedrock and the checker uses Bedrock's 128-block search in the Nether. The platform heights for a forced portal are Java's; Bedrock picks its spot in a similar way.
Does it save my portals?
No. Nothing is stored. Everything you type is kept in the page's address, so copying the link shares the calculation, and nothing is sent anywhere.