The formula, step by step
Take the dp value, multiply it by the reported dpi, and divide by 160. For example, 48 dp on a 480 dpi phone is 48 x 480 / 160 = 144 px. On a 320 dpi phone the same 48 dp is 96 px. Both are about 7.6 mm on the glass, which is exactly why dp exists: the same layout stays physically consistent across very different panels.
To go the other way, divide px by the same factor: px / (dpi / 160) = dp. A 144 px element on a 480 dpi screen is 144 / 3 = 48 dp.
Non-standard densities still use the same formula
Not every phone reports one of the six standard buckets. A phone reporting 440 dpi still converts with the exact value: 16 dp is 16 x 440 / 160 = 44 px, and 48 dp is 132 px. Resource selection still snaps to the nearest bucket — 440 dpi reads drawable-xxhdpi — but pixel conversion uses the exact reported value. That distinction is why the dp to px converter accepts any dpi, not just 120, 160, 240, 320, 480 and 640.
Density buckets at a glance
The six standard buckets are listed below. They are the scale factors the system uses for drawable folders, and they are also the most common dpi values you will see in the wild.
- ldpi — 120 dpi — 0.75x
- mdpi — 160 dpi — 1x
- hdpi — 240 dpi — 1.5x
- xhdpi — 320 dpi — 2x
- xxhdpi — 480 dpi — 3x
- xxxhdpi — 640 dpi — 4x
dp, sp and px: which one to use
Use dp for layout sizes and spacing, sp for text, and px only when you need an exact pixel count, for example in a custom drawing routine. sp works like dp and then scales again with the user's font-size preference, so text set in sp can overflow a container measured in px if the user has enlarged system text.
To convert a real device, use the dp to px converter, check the device's reported density with adb shell wm density, or look it up in the device database. For the full bucket explanation, see density buckets and drawable folders.