The standard algorithm to convert RGB to HSV normalizes each 8-bit RGB channel by 255, finds the maximum, minimum, and range, then derives hue, saturation, and value while handling achromatic colors explicitly.
RGB describes a color through additive red, green, and blue channel amounts. HSV represents the same sRGB-style color as a position on a color wheel, a saturation measure, and a value measure. This guide focuses on the 8-bit algorithm used for ordinary RGB values from 0 through 255.

Normalize the RGB channels before any HSV branch
Start by validating the input. Each red, green, and blue channel must be a finite whole number from 0 through 255. Strict validation prevents a typo from being silently rounded or clamped into a valid-looking color.
- Normalize the channels: calculate r = R / 255, g = G / 255, and b = B / 255.
- Find the shared values: calculate max = max(r,g,b), min = min(r,g,b), and delta = max - min.
- Calculate value: set V = max. HSV value therefore tracks the strongest normalized channel rather than perceived lightness.
- Calculate saturation: set S = delta / max when max is nonzero; otherwise, set S = 0. This makes black’s saturation explicitly zero instead of attempting an undefined division.
Saturation expresses how far the color sits from the gray axis relative to its value. It is not a general measure of brightness, and HSV value is not interchangeable with HSL lightness.
Select hue from the dominant channel
When delta is nonzero, hue depends on which normalized channel is maximal and on the relative positions of the other two channels. Use the following branches:
- Red is maximal: calculate H = 60 × (((g - b) / delta) mod 6).
- Green is maximal: calculate H = 60 × (((b - r) / delta) + 2).
- Blue is maximal: calculate H = 60 × (((r - g) / delta) + 4).
In the red branch, mod 6 means taking a remainder in the range from 0 up to but not including 6. Reduce the final hue modulo 360 so it remains nonnegative and below 360. The resulting angle follows the familiar wheel positions: red begins at 0 degrees, followed by yellow, green, cyan, blue, and magenta at 60-degree intervals.
Check for delta equal to zero before evaluating these branches. A zero delta means all three channels are equal, so hue has no visual meaning. The standard implementation used here returns the conventional placeholder hue of 0 degrees. If two maximum channels tie, the corresponding standard branches produce the same hue angle.
Run one complete conversion example
- For the RGB triplet (255, 128, 0), normalize the channels to r = 1, g = 128 / 255, and b = 0.
- The maximum is 1, the minimum is 0, and delta is 1 - 0 = 1.
- Value is V = 1, while saturation is S = 1 / 1 = 1.
- Because red is maximal, hue is H = 60 × (((128 / 255) - 0) / 1) = 30.117647… degrees.
- Rounded for display, the result is H = 30.12 degrees, S = 100.00%, and V = 100.00%.
Keep the internal values unrounded through the calculation. Rounding only the final display prevents small intermediate errors from affecting the hue branch or the comparison between channels.
Convert an 8-bit RGB triplet in the browser
- Open the RGB to HSV Converter.
- Enter whole-number red, green, and blue values from 0 through 255 in their corresponding fields.
- Select Convert to HSV.
- Read the hue in degrees and the saturation and value as percentages. The result also includes normalized HSV notation, the source HEX code, and a visual swatch.
- Check whether the destination expects degrees and percentages, zero-to-one fractions, or a compact integer range before transferring the values.
The input channels remain visible, so you can change one value and compare how all three HSV components respond. The conversion runs entirely in the browser and does not save a color history.
Handle achromatic colors and invalid inputs correctly
Achromatic colors require an explicit branch because their hue is undefined even though saturation is well defined as zero.
- Black: all channels are zero, so the maximum, minimum, delta, value, and saturation are zero. Hue is reported with the same conventional placeholder of 0 degrees.
- Equal nonzero channels: the color is gray, delta is zero, and saturation is zero. Value equals the common normalized channel, but hue has no visual meaning and is reported as 0 degrees.
- Invalid input: decimal values, empty fields, negative numbers, values above 255, and nonfinite values produce an explicit error rather than being rounded or clamped.
- Alpha: transparency is outside the converter’s scope because it does not change the RGB-to-HSV calculation for the underlying three channels.
The converter also does not read embedded image profiles or convert between wide-gamut color spaces. It transforms the supplied sRGB-style triplet; it does not attempt to recover the color profile of an original image or normalize an arbitrary color space.
Match the destination’s HSV scale
A mathematically equivalent color can use different numeric encodings in different applications. Confirm the receiving format before copying values from a degrees-and-percentages interface.
| Destination format | Expected representation | Transfer action |
|---|---|---|
| Degrees and percentages | Hue in degrees, with saturation and value expressed as percentages | Use the displayed values directly when the destination documents this format. |
| Zero-to-one fractions | Saturation and value from 0 to 1; hue remains an angle unless the destination specifies otherwise | Divide the displayed saturation and value percentages by 100 after confirming the API’s contract. |
| Compact integer range | Some software stores hue from 0 to 179 or from 0 to 255 | Convert the hue to the program’s documented scale instead of pasting the degree value unchanged. |
| HSL coordinates | HSL uses a different lightness quantity | Use an HSL converter rather than relabeling HSV value as lightness. |
Do not substitute a whole-number percentage for a fractional API value unless that program explicitly expects percentages. Another application may also round the result differently, so its documentation takes priority over assumptions based on the displayed decimals.
Validate the implementation and use the result responsibly
A reliable implementation should preserve both the mathematical order and the edge-case behavior:
- Validate integer boundaries before normalizing the channels.
- Handle a zero maximum and a zero delta before attempting division.
- Keep full floating-point precision until the final formatting step.
- Test the six primary and secondary wheel positions, black, and middle gray as regression cases.
- Keep HSV value distinct from HSL lightness and measured luminance.
The Android Color.colorToHSV documentation defines hue from zero up to but not including 360, with saturation and value represented from 0 to 1. The converter follows that range convention and independently checks its implementation against the R grDevices rgb2hsv convention for typical 0-to-255 sRGB input.
Use the result for CSS exploration, graphics scripting, teaching, palette-coordinate comparisons, or moving an 8-bit sample into an HSV-based control. For a CSS-oriented handoff, review RGB to HSV values for CSS code for the destination-format considerations. A successful color conversion does not establish text readability; test an actual foreground and background pair with a dedicated contrast checker.
Related reading: How Do I Check the Result After CMYK to RGB Conversion?.