Two envelopes paradox calculator
See the arithmetic behind the two envelopes paradox: keeping the opened envelope is worth exactly what you saw, while switching appears worth 1.25 times as much under the classic half-or-double model. Both cases are shown side by side. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Amount
- 20
- Other half
- 10
- Other double
- 40
- Expected keep
- 20
- Expected switch
- 25
The two envelopes paradox is a classic puzzle in probability and decision theory: you are shown two indistinguishable envelopes, one of which holds twice as much money as the other. After you open one envelope and see a positive amount, a naive calculation appears to show that switching is always better, because the unseen envelope seems equally likely to hold half or double. This calculator takes the opened amount and reports both expected values under that classic equal-probability model: the expected value of keeping the opened envelope, which is the amount itself, and the expected value of switching, which is one and a quarter times the amount.
What the two envelopes paradox computes and why both expectations appear
The two envelopes paradox begins with a pair of sealed envelopes. One envelope holds twice as much money as the other, and you are invited to pick one at random. After you open your chosen envelope and observe a positive amount A, a tempting argument says you should switch.
The unseen envelope, the argument claims, is equally likely to contain half of A or twice A, so the expected value of switching is one half times A over two plus one half times two A, which simplifies to one and a quarter times A. The expected value of keeping what you already see is just A. Because 1.25 A is larger than A for every positive A, switching appears strictly better no matter what you found.
That unconditional recommendation is the paradox: the setup is symmetric, so the same argument would have applied if you had opened the other envelope first, and both parties cannot each gain in expectation by swapping. This calculator does not try to dissolve the philosophical dispute about priors, improper distributions, or whether the half-or-double probabilities can really be one half after A is observed. It computes the two expected values under the classic equal-probability switch model so students, writers, and tutors can inspect the arithmetic that creates the puzzle.
You supply the opened amount; the tool returns the keep expectation, the switch expectation, the half and double alternatives, and the apparent advantage of switching. The arithmetic is deterministic and never samples random envelopes.
Where these two expected values are useful
Classrooms and tutoring platforms use a two envelopes paradox calculator so learners can check both expected values for an arbitrary opened amount without mixing up the half and double cases by hand. Philosophy and decision-theory articles need a deterministic oracle that prints 1.25 A versus A for any positive stake, so a figure or homework key never drifts from a spreadsheet typo. Failed validation does not consume balance.
Keep requests small, pin the cleaned floating fields in tests, and you get reproducible keep and switch expectations for homework, lecture demos, and edge workers without standing up a probability library of your own.
What you can do with it
Classroom and homework checks
Let students submit an opened envelope amount and verify both expected values: keep equals A, switch equals 1.25 A, with the half and double alternatives shown.
Decision-theory articles and lecture notes
Generate the classic 1.25 A versus A comparison for any positive stake so figures and keys stay consistent with the equal-probability switch model.
FAQ
How are the two expected values computed?
Given a positive opened amount A, the other envelope is treated as A/2 or 2A with equal probability. E[keep] is A. E[switch] is 0.5×(A/2) + 0.5×(2A) = 1.25A.
Why does switching look better than keeping?
Under the classic model the switch expectation is always 1.25 times the opened amount, so it exceeds the keep expectation for every A>0. That unconditional recommendation is the paradox; the calculator reports both numbers rather than dissolving the debate.
Does this resolve the two envelopes paradox?
No. It computes the classic equal-probability switch arithmetic that creates the puzzle.
What happens if I enter zero or a negative amount?
The calculator rejects it. An opened envelope in this puzzle always holds a positive amount, so zero or a negative number is treated as an input mistake rather than as an expected value of zero.
If switching looks better, why not switch back again?
Because the same argument would apply to the other envelope too, so you would keep swapping forever. The setup is symmetric and both envelopes cannot each be the better choice, which is exactly what makes it a paradox.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/stat/two-envelopes-paradox \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"amount":20}'const res = await fetch("https://api.kit.forhosting.com/stat/two-envelopes-paradox", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"amount": 20
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/two-envelopes-paradox",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"amount": 20
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/two-envelopes-paradox", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"amount":20}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"amount":20}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/two-envelopes-paradox", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"amount": 20
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.two_envelopes_paradox",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The comparison is deterministic, needs no random draws, and rejects non-positive amounts so a classroom or API client never treats a zero or negative stake as a valid paradox instance.
Input contract, response shape, and error behaviour
Zero and negative values also fail, because a non-positive stake is not a valid opened envelope in this model and must not be treated as a successful zero expectation. Those failures are not billed. POST a JSON body with one required positive finite number: amount, the money you observed in the opened envelope. The field may arrive as a JSON number or as a numeric string; aliases value, a, and opened are accepted and resolved to the same canonical amount. Missing fields, empty strings, non-numeric text, Infinity, and NaN fail with invalid_input naming amount. On success the body echoes amount, then other_half as A divided by two and other_double as two times A, the two equally likely contents of the closed envelope. expected_keep is A, the expected value of staying. expected_switch is one half times the half plus one half times the double, which is 1.25 A. switch_advantage is the difference, 0.25 A, and formula restates the identity for display. Example: amount twenty yields other_half ten, other_double forty, expected_keep twenty, expected_switch twenty-five, and switch_advantage five. Pair the numbers with your own essay or lecture notes if you need the Bayesian resolution; this endpoint is deliberately the classic switch arithmetic, not a prior over the smaller amount and not a Monte Carlo of many envelope pairs.
Where a two-envelope expected-value API earns its keep
Exam-prep generators and LMS plugins can mark a short item that asks for the switch expectation given A, and they can treat a non-positive amount as invalid_input instead of a silent zero that a buggy grader might score as correct.
Integration use cases
Exam and LMS auto-grading
Mark two-envelope items with a deterministic oracle that rejects a non-positive amount as invalid_input and never invents an expected value for a zero stake.
Technical questions
What happens if the amount is zero or negative?
The task fails with invalid_input. A non-positive opened amount is not a valid envelope in this model, so the request is rejected and is not billed.
What does the two envelopes paradox calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.