Solve for speed, duration, or length of travel using the D = R × T formula.
Distance (D)
Rate / Speed (R)
Time (T)
mph
km/h
m/s
Hours
Minutes
Seconds
Calculation Result
Understanding the Rate Time Distance Formula
The relationship between speed, time, and distance is a fundamental concept in physics and mathematics. Whether you are planning a road trip, calculating your running pace, or tracking a flight, the formula is always the same: Distance = Rate × Time (d = r × t).
The Components:
Distance (d): The total length of the path traveled (e.g., miles, kilometers, meters).
Rate (r): The speed at which an object moves (e.g., miles per hour, meters per second).
Time (t): The duration for which the object is moving (e.g., hours, minutes, seconds).
How to Use This Calculator
Depending on which piece of information you are missing, you can rearrange the formula:
To find Distance: Multiply Rate by Time (D = R × T).
To find Rate (Speed): Divide Distance by Time (R = D / T).
To find Time: Divide Distance by Rate (T = D / R).
Real-World Examples
Example 1 (Solving for Distance): You drive at a constant rate of 65 mph for 3.5 hours.
Calculation: 65 × 3.5 = 227.5 miles.
Example 2 (Solving for Speed): A marathon runner completes 26.2 miles in 4 hours.
Calculation: 26.2 / 4 = 6.55 miles per hour.
Example 3 (Solving for Time): A train needs to travel 300 km and moves at 120 km/h.
Calculation: 300 / 120 = 2.5 hours.
function updateFields() {
var mode = document.getElementById("solveFor").value;
var label1 = document.getElementById("label1");
var label2 = document.getElementById("label2");
var unit1 = document.getElementById("unit1");
var unit2 = document.getElementById("unit2");
// Clear previous results when switching
document.getElementById("rtdResult").style.display = "none";
document.getElementById("val1").value = "";
document.getElementById("val2").value = "";
if (mode === "distance") {
label1.innerText = "Rate (Speed)";
label2.innerText = "Time (Duration)";
unit1.innerHTML = 'mphkm/hm/s';
unit2.innerHTML = 'HoursMinutesSeconds';
} else if (mode === "rate") {
label1.innerText = "Distance";
label2.innerText = "Time (Duration)";
unit1.innerHTML = 'MilesKilometersMeters';
unit2.innerHTML = 'HoursMinutesSeconds';
} else if (mode === "time") {
label1.innerText = "Distance";
label2.innerText = "Rate (Speed)";
unit1.innerHTML = 'MilesKilometersMeters';
unit2.innerHTML = 'mphkm/hm/s';
}
}
function calculateRTD() {
var mode = document.getElementById("solveFor").value;
var val1 = parseFloat(document.getElementById("val1").value);
var val2 = parseFloat(document.getElementById("val2").value);
var u1 = document.getElementById("unit1").value;
var u2 = document.getElementById("unit2").value;
var resultText = document.getElementById("resultText");
var formulaText = document.getElementById("formulaUsed");
var resultBox = document.getElementById("rtdResult");
if (isNaN(val1) || isNaN(val2) || val1 <= 0 || val2 <= 0) {
alert("Please enter valid positive numbers for both fields.");
return;
}
var result = 0;
var unitLabel = "";
var formula = "";
if (mode === "distance") {
// Distance = Rate * Time
// Convert time to base (hours) if units aren't hours for consistency with mph/kph
var timeInHours = val2;
if (u2 === "minutes") timeInHours = val2 / 60;
if (u2 === "seconds") timeInHours = val2 / 3600;
result = val1 * timeInHours;
if (u1 === "mph") unitLabel = "Miles";
else if (u1 === "kph") unitLabel = "Kilometers";
else if (u1 === "mps") {
// If m/s, convert result to meters based on actual seconds
var timeInSeconds = val2;
if (u2 === "hours") timeInSeconds = val2 * 3600;
if (u2 === "minutes") timeInSeconds = val2 * 60;
result = val1 * timeInSeconds;
unitLabel = "Meters";
}
formula = "Distance = Rate (" + val1 + ") × Time (" + timeInHours.toFixed(4) + " hours)";
}
else if (mode === "rate") {
// Rate = Distance / Time
var timeInHours = val2;
if (u2 === "minutes") timeInHours = val2 / 60;
if (u2 === "seconds") timeInHours = val2 / 3600;
result = val1 / timeInHours;
if (u1 === "miles") unitLabel = "mph";
else if (u1 === "km") unitLabel = "km/h";
else if (u1 === "meters") {
// If meters, maybe they want m/s?
var timeInSeconds = val2;
if (u2 === "hours") timeInSeconds = val2 * 3600;
if (u2 === "minutes") timeInSeconds = val2 * 60;
result = val1 / timeInSeconds;
unitLabel = "m/s";
}
formula = "Rate = Distance (" + val1 + ") / Time (" + timeInHours.toFixed(4) + " hours)";
}
else if (mode === "time") {
// Time = Distance / Rate
result = val1 / val2;
unitLabel = "Hours";
// Handle meters and m/s
if (u1 === "meters" && u2 === "mps") {
unitLabel = "Seconds";
} else if (u2 === "mps") {
// convert miles/km to meters first? No, let's keep it simple: result is in hours unless m/s is used
unitLabel = "Seconds (assuming metric match)";
}
formula = "Time = Distance (" + val1 + ") / Rate (" + val2 + ")";
}
resultText.innerText = result.toLocaleString(undefined, {maximumFractionDigits: 2}) + " " + unitLabel;
formulaText.innerText = "Formula used: " + formula;
resultBox.style.display = "block";
}